net.metanotion.io.block.index
Class IBSkipSpan

java.lang.Object
  extended by net.metanotion.util.skiplist.SkipSpan
      extended by net.metanotion.io.block.index.BSkipSpan
          extended by net.metanotion.io.block.index.IBSkipSpan

public class IBSkipSpan
extends BSkipSpan

I2P version of BSkipSpan BSkipSpan stores all keys and values in-memory, backed by the file. IBSkipSpan stores only the first key, and no values, in-memory. For a get(), here we do a linear search through the span in the file and load only the found value (super() does a binary search in-memory). For a put() or remove(), we load all keys and values for the span from the file, make the modification, flush() out the keys and values, and null out the keys and values in-memory. Recommended span size is 16.

Author:
zzz

Field Summary
 
Fields inherited from class net.metanotion.io.block.index.BSkipSpan
bf, CONT_HEADER_LEN, HEADER_LEN, isKilled, keySer, MAGIC, nextPage, overflowPage, page, prevPage, spanSize, valSer
 
Fields inherited from class net.metanotion.util.skiplist.SkipSpan
keys, MAX_SIZE, next, nKeys, prev, vals
 
Constructor Summary
IBSkipSpan(BlockFile bf, BSkipList bsl, int spanPage, Serializer key, Serializer val)
           
 
Method Summary
 Comparable firstKey()
          Does not call super, we always store first key here
 void flush()
          Flush to disk and null out in-memory keys and values, saving only the first key
 Object get(Comparable key)
          Linear search if in file, Binary search if in memory
 SkipSpan getSpan(Comparable key, int[] search)
          Load whole span from file, do the operation, flush out, then null out in-memory data again.
protected  void loadData()
          I2P - second half of load() Load the whole span's keys and values into memory
 SkipSpan newInstance(SkipList sl)
           
 SkipSpan put(Comparable key, Object val, SkipList sl)
          Load whole span from file, do the operation, flush out, then null out in-memory data again.
 Object[] remove(Comparable key, SkipList sl)
          Load whole span from file, do the operation, flush out, then null out in-memory data again.
(package private)  void seekAndLoadData()
          Seek to the start of the span and load the data Package private so BSkipIterator can call it
 
Methods inherited from class net.metanotion.io.block.index.BSkipSpan
init, killInstance, loadData, loadInit, lostEntries, toString
 
Methods inherited from class net.metanotion.util.skiplist.SkipSpan
getEnd, print
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IBSkipSpan

public IBSkipSpan(BlockFile bf,
                  BSkipList bsl,
                  int spanPage,
                  Serializer key,
                  Serializer val)
           throws IOException
Throws:
IOException
Method Detail

newInstance

public SkipSpan newInstance(SkipList sl)
Overrides:
newInstance in class BSkipSpan

flush

public void flush()
Flush to disk and null out in-memory keys and values, saving only the first key

Overrides:
flush in class BSkipSpan

loadData

protected void loadData()
                 throws IOException
I2P - second half of load() Load the whole span's keys and values into memory

Overrides:
loadData in class BSkipSpan
Throws:
IOException

seekAndLoadData

void seekAndLoadData()
               throws IOException
Seek to the start of the span and load the data Package private so BSkipIterator can call it

Throws:
IOException

firstKey

public Comparable firstKey()
Does not call super, we always store first key here

Overrides:
firstKey in class SkipSpan

getSpan

public SkipSpan getSpan(Comparable key,
                        int[] search)
Load whole span from file, do the operation, flush out, then null out in-memory data again. This is called only via SkipList.find()

Overrides:
getSpan in class SkipSpan

get

public Object get(Comparable key)
Linear search if in file, Binary search if in memory

Overrides:
get in class SkipSpan

put

public SkipSpan put(Comparable key,
                    Object val,
                    SkipList sl)
Load whole span from file, do the operation, flush out, then null out in-memory data again.

Overrides:
put in class SkipSpan
Returns:
the new span if it caused a split, else null if it went in an existing span

remove

public Object[] remove(Comparable key,
                       SkipList sl)
Load whole span from file, do the operation, flush out, then null out in-memory data again.

Overrides:
remove in class SkipSpan
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.