java.lang.Object
net.metanotion.util.skiplist.SkipSpan<K,V>
- Type Parameters:
K- type of keys, must be comparableV- type of values
- All Implemented Interfaces:
Flushable
- Direct Known Subclasses:
BSkipSpan
Represents a span or node in a skip list data structure. Contains arrays of keys and values at a specific level in the skip list.
Field Summary
Constructor Summary
Method Summary
Modifier and TypeMethodDescriptionprivate intbinarySearch(K key) Finds the key among this span's entries.firstKey()Get the first key in this span.voidflush()Flush this span to disk.Get the value associated with the given key.getEnd()Get the end span of this chain.Get the span containing the given key.Insert a span at the given position.voidMark this instance as killed.newInstance(SkipList<K, V> sl) Create a new instance of this span type.print()Dump all data from this span to the end.private voidpushApart(int start) Moves entries right to open a hole.private voidpushTogether(int hole) Moves entries left to close a hole.Put a key-value pair into this span.Object[]Remove a key-value pair from this span.private voidDivides this span in two at a point.
Field Details
MAX_SIZE
public static final int MAX_SIZEMaximum number of entries in a span (limited by BlockFile.spanSize)- See Also:
nKeys
public int nKeysNumber of keys in this spankeys
Array of keysvals
Array of valuesnext
Next and previous spansprev
Previous span
Constructor Details
SkipSpan
protected SkipSpan()Protected constructor for subclasses.SkipSpan
public SkipSpan(int size) Create a new SkipSpan with the specified capacity.- Parameters:
size- the maximum number of key-value pairs- Throws:
IllegalArgumentException- if size too big or too small
Method Details
newInstance
killInstance
public void killInstance()Mark this instance as killed.flush
print
Dump all data from this span to the end.- Returns:
- a string representation of this span and all following spans
binarySearch
Finds the key among this span's entries.- Parameters:
key- the key to look for- Returns:
- where it is, or where it belongs
getEnd
getSpan
get
pushTogether
private void pushTogether(int hole) Moves entries left to close a hole.- Parameters:
hole- the entry removed to make room
pushApart
private void pushApart(int start) Moves entries right to open a hole.- Parameters:
start- where the hole is opened
split
insert
Insert a span at the given position.- Parameters:
loc- the index in this span's key and value arrays to insert atkey- the key to insertval- the value stored under the keysl- the list the entry belongs to, used to create a span on split- Returns:
- the new span if it caused a split, else null if it went in this span
put
remove
Remove a key-value pair from this span.- 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.
firstKey