public interface SortingGopher
SortingAlgorithm for sorting.
These adapters allow us to use generic array-sorting 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 and reasonable random-access swaps, so it is inappropriate for linked lists, variable-length record data files, etc. It is extremely effective at sorting 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 SortingGopher 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.
| Modifier and Type | Method and Description |
|---|---|
int |
compare(int index)
Compares the key of the item at the given index with the current
remembered key.
|
void |
remember(int index)
Remembers the key value at the given index for future comparisons.
|
int |
size()
Returns the number of items in the array.
|
void |
swap(int a,
int b)
Swaps the order of the items at the two given index positions.
|
void remember(int index)
index - index of key value to rememberint compare(int index)
index - index of key value to compare to remembered key valueint size()
void swap(int a,
int b)
a - first index to swapb - second index to swap