java.lang.Object
net.metanotion.util.skiplist.SkipSpan<K,V>
net.metanotion.io.block.index.BSkipSpan<K,V>
net.metanotion.io.block.index.IBSkipSpan<K,V>
- Type Parameters:
K- type of keys maintained by this skip spanV- type of values stored in this skip span
- All Implemented Interfaces:
Flushable
Memory-efficient SkipList span implementation (I2P version).
Stores only first key in memory to reduce memory usage. Loads keys and values from disk on-demand during operations.
Comparison with BSkipSpan:
- BSkipSpan stores all keys and values in-memory, backed by file
- IBSkipSpan stores only first key, and no values, in-memory
For get(): performs linear search through span in file and loads only found value (super() does binary search in-memory).
For put() or remove(K, SkipList): loads all keys and values for span from file, makes modification, flushes out keys and values, and nulls out keys and values in-memory.
Recommended span size is 16.
Field Summary
Fields inherited from class BSkipSpan
bf, CONT_HEADER_LEN, HEADER_LEN, isKilled, keySer, MAGIC, nextPage, overflowPage, page, prevPage, spanSize, valSerModifier and TypeFieldDescriptionprotected final BlockFileReference to the BlockFilestatic final intContinuation page header length in bytesprotected static final intFixed header length in bytesprotected booleanWhether this span has been killed/deletedprotected Serializer<K> Key serializerprotected static final intMagic number for span pages ("Span")protected intNext page numberprotected intOverflow page numberprotected intPage number of this spanprotected intPrevious page numberprotected intNumber of keys this span can holdprotected Serializer<V> Value serializerConstructor Summary
ModifierConstructorDescriptionprivateIBSkipSpan(BlockFile bf, BSkipList<K, V> bsl) Recreates a span from the file.IBSkipSpan(BlockFile bf, BSkipList<K, V> bsl, int spanPage, Serializer<K> key, Serializer<V> val) Opens the span on the given page and chains the remaining span pages of the list.Method Summary
Modifier and TypeMethodDescriptionfirstKey()Does not call super, we always store first key herevoidflush()Flush to disk and null out in-memory keys and values, saving only the first keyLinear search if in file, Binary search if in memoryprivate VLinear search through the span in the file for the value.Load whole span from file, do the operation, flush out, then null out in-memory data again.protected voidloadData()I2P - second half of load() Load the whole span's keys and values into memoryprivate voidMust already be seeked to the end of the span header via loadInit() orseekData()newInstance(SkipList<K, V> sl) Create a new span instance for a page split.Load whole span from file, do the operation, flush out, then null out in-memory data again.Object[]Load whole span from file, do the operation, flush out, then null out in-memory data again.private voidrepair()Nothing to repair in a B-skip span.(package private) voidSeek to the start of the span and load the data Package private so BSkipIterator can call itprivate voidseekData()Seek past the span headerMethods inherited from class BSkipSpan
init, killInstance, loadData, loadInit, lostEntries, toStringModifier and TypeMethodDescriptionstatic voidInitialize a new span page on disk.voidMark this span instance as killed and free its resources.protected voidloadData(boolean flushOnError) Load the span's keys and values into memory.protected static <X extends Comparable<? super X>, Y>
voidloadInit(BSkipSpan<X, Y> bss, BlockFile bf, BSkipList<X, Y> bsl, int spanPage, Serializer<X> key, Serializer<Y> val) Load the span headers from disk (first half of load()).protected voidlostEntries(int firstBadEntry, int lastGoodPage) Attempt to recover from corrupt data in this span.toString()Get a string representation of this span.
Field Details
firstKey
Smallest key held in this span.
Constructor Details
IBSkipSpan
IBSkipSpan
public IBSkipSpan(BlockFile bf, BSkipList<K, V> bsl, int spanPage, Serializer<K> key, Serializer<V> val) throws IOExceptionOpens the span on the given page and chains the remaining span pages of the list.- Parameters:
bf- the block filebsl- the B-skip listspanPage- page number of the spankey- key serializerval- value serializer- Throws:
IOException- on I/O error
Method Details
newInstance
flush
loadData
I2P - second half of load() Load the whole span's keys and values into memory- Overrides:
loadDatain classBSkipSpan<K extends Comparable<? super K>, V>- Throws:
IOException- if an I/O error occurs
loadFirstKey
Must already be seeked to the end of the span header via loadInit() orseekData()- Throws:
IOException- if the span's data pages cannot be read
seekData
Seek past the span header- Throws:
IOException- if the span was killed or its magic number is wrong
seekAndLoadData
Seek to the start of the span and load the data Package private so BSkipIterator can call it- Throws:
IOException- if the span was killed, its magic is wrong, or a record page cannot be read
getData
Linear search through the span in the file for the value.- Parameters:
key- the key to search for- Returns:
- the value stored under
key, or null if not found - Throws:
IOException- if the span was killed, its magic is wrong, or a record page cannot be read
repair
private void repair()Nothing to repair in a B-skip span.firstKey
getSpan
Load whole span from file, do the operation, flush out, then null out in-memory data again. This is called only viaSkipList.find()get
put
Load whole span from file, do the operation, flush out, then null out in-memory data again.remove
Load whole span from file, do the operation, flush out, then null out in-memory data again.- Overrides:
removein classSkipSpan<K extends Comparable<? super K>, V>- Parameters:
key- the key whose entry is to be deletedsl- the list to shrink if this span empties out- Returns:
- An array of two objects or null. rv[0] is the removed object. rv[1] is the deleted SkipSpan if the removed object was the last in the SkipSpan. rv is null if no object was removed.