java.lang.Object
net.metanotion.util.skiplist.SkipList<K,V>
net.metanotion.io.block.index.BSkipList<K,V>
- Type Parameters:
K- type of keys maintained by this skip listV- type of mapped values
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable, Iterable<V>
public class BSkipList<K extends Comparable<? super K>, V>extends SkipList<K,V> implements Closeable
On-disk SkipList implementation for persistent key-value storage.
Provides efficient indexed storage with logarithmic search performance. Supports multiple spans and levels for scalable data organization.
On-disk format:
Magic number (long) first span page (unsigned int) first level page (unsigned int) size (unsigned int) spans (unsigned int) levels (unsigned int)
Always fits on one page.
Field Summary
Modifier and TypeFieldDescriptionfinal BlockFileReference to the BlockFileprivate final booleanTrue when the list is stored entirely on disk.intPage number of the first levelintPage number of the first spanprivate booleanWhether this skiplist is closed(package private) final HashMap<Integer, SkipLevels<K, V>> Level cacheprivate static final longWritten first in a persisted list, so a wrong file is recognisedintPage number of this skiplist headerSpan cacheFields inherited from class SkipList
first, P, rng, size, stackModifier and TypeFieldDescriptionFirst span in the list.protected static final intThe probability of each next higher level.static final RandomRandom number generator, the I2P one rather than the upstream default.protected intNumber of items in the list.protected SkipLevels<K, V> Level stack above the first span.Constructor Summary
ConstructorsConstructorDescriptionBSkipList(int spanSize, BlockFile bf, int skipPage, Serializer<K> key, Serializer<V> val) Create a BSkipList from a BlockFile.BSkipList(int spanSize, BlockFile bf, int skipPage, Serializer<K> key, Serializer<V> val, boolean fileOnly) Create a BSkipList from a BlockFile.Method Summary
Modifier and TypeMethodDescriptionbooleanbslck(boolean fix, boolean isMeta) Run an integrity check on the skiplist and all the levels in it.voidclose()Close this skiplist and flush all data to disk.voiddelete()Delete this skiplist and free all its pages.Find the entry with the given key.voidflush()Flush all data to disk.static voidInitialize a new skiplist on disk.iterator()Get an iterator over all entries in this skiplist.intCalculate the maximum number of levels for this skiplist.toString()Get a string representation of this skiplist.Methods inherited from class SkipList
addItem, balance, delItem, generateColHeight, get, put, remove, sizeModifier and TypeMethodDescriptionvoidaddItem()Increment item count.voidbalance()Rebalance the skip list levels, adjusted to guarantee O(log n) searches.voiddelItem()Decrement item count, minimum zero.intChoose the column height for a newly inserted node, using the geometric distribution that keeps the list's search cost logarithmic.Get the value for a key.voidInsert or update a key-value pair in the skip list.Remove a key-value pair from the skip list.intsize()Return the number of items.Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
Field Details
MAGIC
private static final long MAGICWritten first in a persisted list, so a wrong file is recognised- See Also:
firstSpanPage
public int firstSpanPagePage number of the first spanfirstLevelPage
public int firstLevelPagePage number of the first levelskipPage
public int skipPagePage number of this skiplist headerbf
Reference to the BlockFileisClosed
private boolean isClosedWhether this skiplist is closedspanHash
levelHash
Level cachefileOnly
private final boolean fileOnlyTrue when the list is stored entirely on disk.
Constructor Details
BSkipList
public BSkipList(int spanSize, BlockFile bf, int skipPage, Serializer<K> key, Serializer<V> val) throws IOException Create a BSkipList from a BlockFile.- Parameters:
spanSize- the size of spansbf- the backing file; the skiplist header and spans are read from and written to its pagesskipPage- the page number of this skiplistkey- the key serializerval- the value serializer- Throws:
IOException- if an I/O error occurs
BSkipList
public BSkipList(int spanSize, BlockFile bf, int skipPage, Serializer<K> key, Serializer<V> val, boolean fileOnly) throws IOException Create a BSkipList from a BlockFile.- Parameters:
spanSize- the size of spansbf- the backing file; the skiplist header and spans are read from and written to its pagesskipPage- the page number of this skiplistkey- the key serializerval- the value serializerfileOnly- if true, only read from file (no caching)- Throws:
IOException- if an I/O error occurs
Method Details
close
public void close()Close this skiplist and flush all data to disk.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
flush
delete
Delete this skiplist and free all its pages. Must be open (do not callclose()first).- Throws:
IOException- if an I/O error occurs
init
Initialize a new skiplist on disk.- Parameters:
bf- the backing file; the skiplist header and spans are read from and written to its pagespage- the page number for the skiplist headerspanSize- the span size to use- Throws:
IOException- if an I/O error occurs
maxLevels
iterator
Get an iterator over all entries in this skiplist.- Specified by:
iteratorin interfaceIterable<K extends Comparable<? super K>>- Overrides:
iteratorin classSkipList<K extends Comparable<? super K>, V>- Returns:
- a cached iterator when
fileOnlyis false, otherwise anIBSkipIteratorthat reads spans from disk
find
Find the entry with the given key.bslck
public boolean bslck(boolean fix, boolean isMeta) Run an integrity check on the skiplist and all the levels in it.- Parameters:
fix- if true, attempt to fix any corruption foundisMeta- if true, this is a metaindex skiplist- Returns:
- true if the levels were modified.
toString