Class BlindSearch
- java.lang.Object
-
- com.mckoi.database.SelectableScheme
-
- com.mckoi.database.BlindSearch
-
public final class BlindSearch extends SelectableScheme
This is a scheme that performs a blind search of a given set. It records no information about how a set element relates to the rest. It blindly searches through the set to find elements that match the given criteria.This scheme performs badly on large sets because it requires that the database is queried often for information. However since it records no information about the set, memory requirements are non-existant.
This scheme should not be used for anything other than small domain sets because the performance suffers very badly with larger sets. It is ideal for small domain sets because of its no memory overhead. For any select operation this algorithm must check every element in the set.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
BlindSearch.RangeChecker
Object used to during range check loop.
-
Field Summary
-
Fields inherited from class com.mckoi.database.SelectableScheme
EMPTY_LIST, ONE_LIST
-
-
Constructor Summary
Constructors Constructor Description BlindSearch(TableDataSource table, int column)
The Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SelectableScheme
copy(TableDataSource table, boolean immutable)
Returns an exact copy of this scheme including any optimization information.void
dispose()
Disposes and invalidates the BlindSearch.private void
doInsertSort(IntegerVector vec, int row)
private int
highestSearch(TObject ob, IntegerVector vec, int lower, int higher)
Searches for a given TObject (ob) in the row list between the two bounds.void
insert(int row)
This scheme doesn't take any notice of insertions or removals.void
readFrom(java.io.InputStream in)
Reads the entire state of the scheme from the input stream.void
remove(int row)
This scheme doesn't take any notice of insertions or removals.private int
search(TObject ob, IntegerVector vec, int lower, int higher)
We implement an insert sort algorithm here.IntegerVector
selectAll()
These are the select operations that are the main purpose of the scheme.IntegerVector
selectRange(SelectableRange range)
Selects the given range of values from this index.IntegerVector
selectRange(SelectableRange[] ranges)
Selects a set of ranges from this index.void
writeTo(java.io.OutputStream out)
Writes the entire state of the scheme to the output stream.-
Methods inherited from class com.mckoi.database.SelectableScheme
Debug, getCellContents, getColumn, getSubsetScheme, getSystem, getTable, internalOrderIndexSet, isImmutable, selectAllNonNull, selectBetween, selectEqual, selectFirst, selectGreater, selectGreaterOrEqual, selectLast, selectLess, selectLessOrEqual, selectNotEqual, selectNotFirst, selectNotLast, setImmutable, toString
-
-
-
-
Constructor Detail
-
BlindSearch
public BlindSearch(TableDataSource table, int column)
The Constructor.
-
-
Method Detail
-
insert
public void insert(int row)
This scheme doesn't take any notice of insertions or removals.- Specified by:
insert
in classSelectableScheme
-
remove
public void remove(int row)
This scheme doesn't take any notice of insertions or removals.- Specified by:
remove
in classSelectableScheme
-
readFrom
public void readFrom(java.io.InputStream in) throws java.io.IOException
Reads the entire state of the scheme from the input stream. This is a trivial case for BlindSearch which doesn't require any data to be stored.- Specified by:
readFrom
in classSelectableScheme
- Throws:
java.io.IOException
-
writeTo
public void writeTo(java.io.OutputStream out) throws java.io.IOException
Writes the entire state of the scheme to the output stream. This is a trivial case for BlindSearch which doesn't require any data to be stored.- Specified by:
writeTo
in classSelectableScheme
- Throws:
java.io.IOException
-
copy
public SelectableScheme copy(TableDataSource table, boolean immutable)
Returns an exact copy of this scheme including any optimization information. The copied scheme is identical to the original but does not share any parts. Modifying any part of the copied scheme will have no effect on the original and vice versa.- Specified by:
copy
in classSelectableScheme
-
dispose
public void dispose()
Disposes and invalidates the BlindSearch.- Specified by:
dispose
in classSelectableScheme
-
search
private int search(TObject ob, IntegerVector vec, int lower, int higher)
We implement an insert sort algorithm here. Each new row is inserted into our row vector at the sorted corrent position. The algorithm assumes the given vector is already sorted. We then just subdivide the set until we can insert at the required position.
-
highestSearch
private int highestSearch(TObject ob, IntegerVector vec, int lower, int higher)
Searches for a given TObject (ob) in the row list between the two bounds. This will return the highest row of the set of values that are equal to 'ob'.This returns the place to insert ob into the vector, it should not be used to determine if ob is in the list or not.
-
doInsertSort
private void doInsertSort(IntegerVector vec, int row)
-
selectAll
public IntegerVector selectAll()
Description copied from class:SelectableScheme
These are the select operations that are the main purpose of the scheme. They retrieve the given information from the set. Different schemes will have varying performance on different types of data sets. The select operations must *always* return a resultant row set that is sorted from lowest to highest.- Overrides:
selectAll
in classSelectableScheme
-
selectRange
public IntegerVector selectRange(SelectableRange range)
Description copied from class:SelectableScheme
Selects the given range of values from this index. The SelectableRange must contain a 'start' value that compares <= to the 'end' value.This must guarentee that the returned set is sorted from lowest to highest value.
- Specified by:
selectRange
in classSelectableScheme
-
selectRange
public IntegerVector selectRange(SelectableRange[] ranges)
Description copied from class:SelectableScheme
Selects a set of ranges from this index. The ranges must not overlap and each range must contain a 'start' value that compares <= to the 'end' value. Every range in the array must represent a range that's lower than the preceeding range (if it exists).If the above rules are enforced (as they must be) then this method will return a set that is sorted from lowest to highest value.
This must guarentee that the returned set is sorted from lowest to highest value.
- Specified by:
selectRange
in classSelectableScheme
-
-