java.lang.Object
net.metanotion.util.skiplist.SkipLevels<K,V>
net.metanotion.io.block.index.BSkipLevels<K,V>
- Type Parameters:
K- the type of keys maintained by this skip level structureV- the type of mapped values
- All Implemented Interfaces:
Flushable
SkipList level management for multi-level indexing.
Manages hierarchical structure of SkipList levels to provide efficient search paths through data structure.
On-disk format:
Magic number (long) max height (unsigned short) non-null height (unsigned short) span page (unsigned int) height number of level pages (unsigned ints)
Always fits on one page.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classBSkipLevels.LevelComparator<K extends Comparable<? super K>, V>Comparator for sorting levels inblvlfix().Field Summary
Modifier and TypeFieldDescriptionfinal BlockFileReference to the BlockFileReference to the BSkipList(package private) static final intFixed header length in bytesprivate booleanWhether this level has been killedfinal intPage number of this levelprivate final int[]The level pages, passed from the constructor toinitializeLevels()private static final longWritten first in a persisted level, so a wrong file is recognisedfinal intPage number of the associated spanConstructor Summary
ConstructorsConstructorDescriptionBSkipLevels(BlockFile bf, int levelPage, BSkipList<K, V> bsl) Create a BSkipLevels and load it from disk.Method Summary
Modifier and TypeMethodDescriptionbooleanblvlck(boolean fix) Run an integrity check on this level.booleanblvlck(boolean fix, int width, SkipLevels<K, V>[] prevLevels) Run an integrity check on this level with additional parameters.private booleanblvlfix()Fix the levels.voidflush()Flush this level to disk.private voidgetAllLevels(SkipLevels<K, V> l, Set<SkipLevels<K, V>> lvlSet) Breadth-first, sortof We assume everything is findable from the root levelstatic voidInitialize a new BSkipLevels page on disk.voidNon-recursive initializer.private voidinitializeLevels(List<BSkipLevels<K, V>> nextInit) Non-recursive initializer.voidMark this level as killed and free its resources.SkipLevels<K, V> Create a new instance of this level type.toString()Get a string representation of this level.Methods inherited from class SkipLevels
get, getEnd, getSpan, key, print, printAll, put, removeModifier and TypeMethodDescriptionGet the value associated with the given key.getEnd()Get the end span of this level.Get the span containing or following the given key.key()Get the key at the bottom of this level.print()Print this level and all levels below it.printAll()Print this level and all levels below it, recursively.SkipLevels<K, V> Put a key-value pair into the skip list.Object[]Remove a key-value pair from the skip list.
Field Details
MAGIC
private static final long MAGICWritten first in a persisted level, so a wrong file is recognised- See Also:
HEADER_LEN
levelPage
public final int levelPagePage number of this levelspanPage
public final int spanPagePage number of the associated spanbf
Reference to the BlockFilebsl
Reference to the BSkipListisKilled
private boolean isKilledWhether this level has been killedlps
private final int[] lpsThe level pages, passed from the constructor toinitializeLevels()
Constructor Details
BSkipLevels
Create a BSkipLevels and load it from disk. Non-recursive initializer initializeLevels() MUST be called on the first BSkipLevel in the skiplist after the constructor, unless it's a new empty level andinit(BlockFile, int, int, int)was previously called.- Parameters:
bf- the BlockFile that owns the page this level is read fromlevelPage- the page number of this levelbsl- the BSkipList this level is registered in, for its levelHash and spanHash caches- Throws:
IOException- if an I/O error occurs
Method Details
initializeLevels
public void initializeLevels()Non-recursive initializer. MUST be called on the first BSkipLevel in the skiplist after the constructor, unless it's a new empty level and init() was previously called. Only call on the first skiplevel in the list!initializeLevels
Non-recursive initializer. MUST be called after constructor.- Parameters:
nextInit- out parameter, next levels to initialize
init
Initialize a new BSkipLevels page on disk.- Parameters:
bf- the BlockFile that the page is allocated frompage- the page numberspanPage- the span page numbermaxHeight- the maximum height- Throws:
IOException- if an I/O error occurs
flush
public void flush()Flush this level to disk.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classSkipLevels<K extends Comparable<? super K>, V>
killInstance
public void killInstance()Mark this level as killed and free its resources.- Overrides:
killInstancein classSkipLevels<K extends Comparable<? super K>, V>
newInstance
Create a new instance of this level type.- Overrides:
newInstancein classSkipLevels<K extends Comparable<? super K>, V>- Parameters:
levels- the number of levelsss- the SkipSpan whose page this level is built abovesl- the SkipList that owns this level- Returns:
- a new BSkipLevels instance
blvlck
public boolean blvlck(boolean fix) Run an integrity check on this level.- Overrides:
blvlckin classSkipLevels<K extends Comparable<? super K>, V>- Parameters:
fix- if true, attempt to fix corruption- Returns:
- true if the levels were modified
blvlfix
private boolean blvlfix()Fix the levels. Only call from the first level. Primarily to fix nulls in levels caused by previous SkipLevels bug. This should handle dups and loops and out-of-order levels too, but those may cause problems before this in the constructor. This is fast enough to call every time the skiplist is opened.- Returns:
- true if the levels were modified.
getAllLevels
Breadth-first, sortof We assume everything is findable from the root level- Parameters:
l- non-nulllvlSet- out parameter, the result
blvlck
Run an integrity check on this level with additional parameters.- Overrides:
blvlckin classSkipLevels<K extends Comparable<? super K>, V>- Parameters:
fix- if true, attempt to fix corruptionwidth- the current widthprevLevels- previous levels to check- Returns:
- true if corruption was found
toString