Package com.mckoi.database
Class InsertSearch
java.lang.Object
com.mckoi.database.SelectableScheme
com.mckoi.database.CollatedBaseSearch
com.mckoi.database.InsertSearch
This is a SelectableScheme similar in some ways to the binary tree. When
a new row is added, it is inserted into a sorted list of rows. We can then
use this list to select out the sorted list of elements.
This requires less memory than the BinaryTree, however it is not as fast. Even though, it should still perform fairly well on medium size data sets. On large size data sets, insert and remove performance may suffer.
This object retains knowledge of all set elements unlike BlindSearch which has no memory overhead.
Performance should be very comparable to BinaryTree for sets that aren't altered much.
- Author:
- Tobias Downer
-
Field Summary
Fields inherited from class com.mckoi.database.SelectableScheme
EMPTY_LIST, ONE_LIST -
Constructor Summary
ConstructorsConstructorDescriptionInsertSearch(TableDataSource table, int column) The Constructor.InsertSearch(TableDataSource table, int column, IntegerVector vec) Constructor sets the scheme with a pre-sorted list. -
Method Summary
Modifier and TypeMethodDescriptionprotected IntegerVectoraddRangeToSet(int start, int end, IntegerVector ivec) Adds the set indexes to the list that represent the range of values between the start (inclusive) and end offset (inclusive) given.copy(TableDataSource table, boolean immutable) Returns an exact copy of this scheme including any optimization information.voiddispose()Disposes this scheme.protected TObjectReturns the first value of this column (in collated order).voidinsert(int row) Inserts a row into the list.protected TObjectReturns the last value of this column (in collated order).voidreadFrom(InputStream in) Reads the entire state of the scheme from the input stream.voidremove(int row) Removes a row from the list.protected intsearchFirst(TObject val) Finds the position in the collated set of the first value in the column equal to the given value.protected intsearchLast(TObject val) Finds the position in the collated set of the last value in the column equal to the given value.The select operations for this scheme.protected intsetSize()The size of the set (the number of rows in this column).voidwriteTo(OutputStream out) Writes the entire state of the scheme to the output stream.Methods inherited from class com.mckoi.database.CollatedBaseSearch
selectRange, selectRangeMethods 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 Details
-
InsertSearch
The Constructor. -
InsertSearch
Constructor sets the scheme with a pre-sorted list. The Vector 'vec' should not be used again after this is called. 'vec' must be sorted from low key to high key.
-
-
Method Details
-
insert
public void insert(int row) Inserts a row into the list. This will always be thread safe, table changes cause a write lock which prevents reads while we are writing to the table.- Overrides:
insertin classCollatedBaseSearch
-
remove
public void remove(int row) Removes a row from the list. This will always be thread safe, table changes cause a write lock which prevents reads while we are writing to the table.- Overrides:
removein classCollatedBaseSearch
-
readFrom
Reads the entire state of the scheme from the input stream. Throws an exception if the scheme is not empty.- Overrides:
readFromin classCollatedBaseSearch- Throws:
IOException
-
writeTo
Writes the entire state of the scheme to the output stream.- Overrides:
writeToin classCollatedBaseSearch- Throws:
IOException
-
copy
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:
copyin classSelectableScheme
-
dispose
public void dispose()Disposes this scheme.- Overrides:
disposein classCollatedBaseSearch
-
searchFirst
Description copied from class:CollatedBaseSearchFinds the position in the collated set of the first value in the column equal to the given value. If the value is not to be found in the column, it returns -(insert_position + 1).- Specified by:
searchFirstin classCollatedBaseSearch
-
searchLast
Description copied from class:CollatedBaseSearchFinds the position in the collated set of the last value in the column equal to the given value. If the value is not to be found in the column, it returns -(insert_position + 1).- Specified by:
searchLastin classCollatedBaseSearch
-
setSize
protected int setSize()Description copied from class:CollatedBaseSearchThe size of the set (the number of rows in this column).- Overrides:
setSizein classCollatedBaseSearch
-
firstInCollationOrder
Description copied from class:CollatedBaseSearchReturns the first value of this column (in collated order). For example, if the column contains (1, 4, 8} then '1' is returned.- Overrides:
firstInCollationOrderin classCollatedBaseSearch
-
lastInCollationOrder
Description copied from class:CollatedBaseSearchReturns the last value of this column (in collated order). For example, if the column contains (1, 4, 8} then '8' is returned.- Overrides:
lastInCollationOrderin classCollatedBaseSearch
-
addRangeToSet
Description copied from class:CollatedBaseSearchAdds the set indexes to the list that represent the range of values between the start (inclusive) and end offset (inclusive) given.- Overrides:
addRangeToSetin classCollatedBaseSearch
-
selectAll
The select operations for this scheme.- Overrides:
selectAllin classCollatedBaseSearch
-