com.partnersoft.data
Interface SearchingGopher


public interface SearchingGopher

Generic adapter to present array-like structures to instances of SearchingAlgorithm for searching.

These adapters allow us to use generic array-searching algorithms on a variety of structures, including disk-based ones, without substantial additional memory overhead. It does assume a data model that allows fast random-access reads, so it is inappropriate for linked lists, variable-length record data files, etc. It is extremely effective at searching fixed-length records and indexes, and makes the comparison an implementation detail that can be optimized internally (e.g. byte comparisons rather instantiating Strings).

It uses an abstract memory register to store values for comparison later. This means that a SearchingGopher must store some kind of state to do the comparison, in addition to any state required to access the underlying data. Since most algorithms collect and repeatedly compare against a minimum or maximum key value, this allows a single read to store the key value, instead of re-reading the item each time a comparison is called for.

Copyright 2003-2006 Partner Software, Inc.

Author:
Paul Reavis

Method Summary
 int compare(int index)
          Compares the key of the item at the given index with the current remembered key.
 void remember(java.lang.Object key)
          Remembers the given value for future comparisons.
 int size()
          Returns the number of items in the array.
 

Method Detail

remember

void remember(java.lang.Object key)
Remembers the given value for future comparisons. This is generally the search key value.

Parameters:
key - key value to remember

compare

int compare(int index)
Compares the key of the item at the given index with the current remembered key.

Parameters:
index - index of key value to compare to remembered key value
Returns:
value < 0 if less than, 0 if equal, > 0 if greater than.

size

int size()
Returns the number of items in the array.

Returns:
number of items - top index is therefore (size-1)