public class BinarySearch extends java.lang.Object implements SearchingAlgorithm
This search method requires that keys be presorted in order; however it is very fast and reliable.
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.binarySearch(SearchingGopher, Object); that is actually
the recommended method.
Copyright 2000-2006 Partner Software, Inc.
| Constructor and Description |
|---|
BinarySearch()
Creates a new BinarySearch algorithm object.
|
| Modifier and Type | Method and Description |
|---|---|
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 BinarySearch |
standardInstance()
Returns a singleton shared instance.
|
public BinarySearch()
standardInstance() method.public static BinarySearch standardInstance()
public int search(SearchingGopher gopher, java.lang.Object key)
SearchingAlgorithmsearch in interface SearchingAlgorithmgopher - adapter to underlying array-like structurekey - value to search forpublic int search(SearchingGopher gopher, java.lang.Object key, int start, int end)
SearchingAlgorithmsearch 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 int findClosest(SearchingGopher gopher, java.lang.Object key)
SearchingAlgorithmfindClosest in interface SearchingAlgorithmgopher - adapter to underlying array-like structurekey - value to search forpublic int findClosest(SearchingGopher gopher, java.lang.Object key, int start, int end)
SearchingAlgorithmfindClosest 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)