|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.partnersoft.data.LinearSearch
public class LinearSearch
A generic linear full-scan search.
This search method is generally used by other methods, or by sorting
algorithms. It does not assume that the keys are in order. However, it is
very slow for worst-case, so you should pre-sort your array and use
BinarySearch or some other algorithm instead.
This isn't declared as a singleton, since it has no actual overhead (no
state), so there's not strong reason to limit instantiation. However an
standardInstance() method is provided that provides a shared
instance.
You can also just use this via the handy convenience method
SearchingLib.linearSearch(SearchingGopher, Object); that is actually
the recommended method.
Copyright 2004-2006 Partner Software, Inc.
| Constructor Summary | |
|---|---|
LinearSearch()
Creates a new LinearSearch algorithm object. |
|
| Method Summary | |
|---|---|
int |
findClosest(SearchingGopher gopher,
java.lang.Object key)
Finds the slot where the given key would go if it were in there. |
int |
findClosest(SearchingGopher gopher,
java.lang.Object key,
int start,
int end)
Finds the slot where the given key would go if it were in there over the given inclusive range (start <= i <= end). |
int |
search(SearchingGopher gopher,
java.lang.Object key)
Searches for the given key using the given gopher. |
int |
search(SearchingGopher gopher,
java.lang.Object key,
int start,
int end)
Searches for the given key using the given gopher over the given range (start <= i < end). |
static LinearSearch |
standardInstance()
Returns a singleton shared instance. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public LinearSearch()
standardInstance() method.
| Method Detail |
|---|
public static LinearSearch standardInstance()
public final int search(SearchingGopher gopher,
java.lang.Object key)
SearchingAlgorithm
search in interface SearchingAlgorithmgopher - adapter to underlying array-like structurekey - value to search for
public final int search(SearchingGopher gopher,
java.lang.Object key,
int start,
int end)
SearchingAlgorithm
search in interface SearchingAlgorithmgopher - adapter to underlying array-like structurekey - value to search forstart - start of index range, inclusive (start <= i)end - end of index range, exclusive (i < end)
public final int findClosest(SearchingGopher gopher,
java.lang.Object key)
SearchingAlgorithm
findClosest in interface SearchingAlgorithmgopher - adapter to underlying array-like structurekey - value to search for
public final int findClosest(SearchingGopher gopher,
java.lang.Object key,
int start,
int end)
SearchingAlgorithm
findClosest in interface SearchingAlgorithmgopher - adapter to underlying array-like structurekey - value to search forstart - start of index range, inclusive (start <= i)end - end of index range, exclusive (i < end)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||