Class IBSkipSpan<K extends Comparable<? super K>,​V>

  • All Implemented Interfaces:
    Flushable

    public class IBSkipSpan<K extends Comparable<? super K>,​V>
    extends BSkipSpan<K,​V>
    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
    • Method Detail

      • flush

        public void flush()
        Flush to disk and null out in-memory keys and values, saving only the first key
        Specified by:
        flush in interface Flushable
        Overrides:
        flush in class BSkipSpan<K extends Comparable<? super K>,​V>
      • 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 K firstKey()
        Does not call super, we always store first key here
        Overrides:
        firstKey in class SkipSpan<K extends Comparable<? super K>,​V>
      • getSpan

        public SkipSpan<K,​V> getSpan​(K 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<K extends Comparable<? super K>,​V>
      • get

        public V get​(K key)
        Linear search if in file, Binary search if in memory
        Overrides:
        get in class SkipSpan<K extends Comparable<? super K>,​V>
      • put

        public SkipSpan<K,​V> put​(K key,
                                       V val,
                                       SkipList<K,​V> sl)
        Load whole span from file, do the operation, flush out, then null out in-memory data again.
        Overrides:
        put in class SkipSpan<K extends Comparable<? super K>,​V>
        Returns:
        the new span if it caused a split, else null if it went in an existing span
      • remove

        public Object[] remove​(K key,
                               SkipList<K,​V> sl)
        Load whole span from file, do the operation, flush out, then null out in-memory data again.
        Overrides:
        remove in class SkipSpan<K extends Comparable<? super K>,​V>
        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.