com.partnersoft.data
Interface SearchingAlgorithm

All Known Implementing Classes:
BinarySearch, LinearSearch

public interface SearchingAlgorithm

An interface for generic array (indexed item, not necessarily an actual Java array object) searching algorithms.

To use, select an implementation of this, and an instance of SearchingGopher, and then sort away.

The less-than-hardcore should look at SearchingLib since it has convenience functions that make it things much easier.

Copyright 2000-2006 Partner Software, Inc.

Author:
Paul Reavis

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).
 

Method Detail

search

int search(SearchingGopher gopher,
           java.lang.Object key)
Searches for the given key using the given gopher. Returns -1 if the search fails.

Parameters:
gopher - adapter to underlying array-like structure
key - value to search for
Returns:
index of found item, or -1 if search failed

search

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). Returns -1 if the search fails.

Parameters:
gopher - adapter to underlying array-like structure
key - value to search for
start - start of index range, inclusive (start <= i)
end - end of index range, exclusive (i < end)
Returns:
index of found item, or -1 if search failed

findClosest

int findClosest(SearchingGopher gopher,
                java.lang.Object key)
Finds the slot where the given key would go if it were in there. Always returns something. Useful for insertion-based structures, or for near-match searches.

Parameters:
gopher - adapter to underlying array-like structure
key - value to search for
Returns:
index of found item, or index where found item would be inserted if it were there

findClosest

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). Always returns something. Useful for insertion-based structures, or for near-match searches.

Parameters:
gopher - adapter to underlying array-like structure
key - value to search for
start - start of index range, inclusive (start <= i)
end - end of index range, exclusive (i < end)
Returns:
index of found item, or index where found item would be inserted if it were there