Class Cursor<K,​V>

  • Type Parameters:
    K - the key type
    V - the value type
    All Implemented Interfaces:
    java.util.Iterator<K>

    public final class Cursor<K,​V>
    extends java.lang.Object
    implements java.util.Iterator<K>
    A cursor to iterate over elements in ascending or descending order.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      K getKey()
      Get the last read key if there was one.
      (package private) Page<K,​V> getPage()
      Get the page where last retrieved key is located.
      V getValue()
      Get the last read value if there was one.
      boolean hasNext()  
      K next()  
      void skip​(long n)
      Skip over that many entries.
      (package private) static <K,​V>
      CursorPos<K,​V>
      traverseDown​(Page<K,​V> page, K key, boolean reverse)
      Fetch the next entry that is equal or larger than the given key, starting from the given page.
      private static <K,​V>
      int
      upperBound​(Page<K,​V> page)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining, remove
    • Field Detail

      • reverse

        private final boolean reverse
      • to

        private final K to
      • current

        private K current
      • last

        private K last
      • lastValue

        private V lastValue
      • lastPage

        private Page<K,​V> lastPage
    • Constructor Detail

      • Cursor

        public Cursor​(RootReference<K,​V> rootReference,
                      K from,
                      K to,
                      boolean reverse)
        Parameters:
        rootReference - of the tree
        from - starting key (inclusive), if null start from the first / last key
        to - ending key (inclusive), if null there is no boundary
        reverse - true if tree should be iterated in key's descending order
    • Method Detail

      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<K>
      • next

        public K next()
        Specified by:
        next in interface java.util.Iterator<K>
      • getKey

        public K getKey()
        Get the last read key if there was one.
        Returns:
        the key or null
      • getValue

        public V getValue()
        Get the last read value if there was one.
        Returns:
        the value or null
      • getPage

        Page<K,​V> getPage()
        Get the page where last retrieved key is located.
        Returns:
        the page
      • skip

        public void skip​(long n)
        Skip over that many entries. This method is relatively fast (for this map implementation) even if many entries need to be skipped.
        Parameters:
        n - the number of entries to skip
      • traverseDown

        static <K,​V> CursorPos<K,​V> traverseDown​(Page<K,​V> page,
                                                             K key,
                                                             boolean reverse)
        Fetch the next entry that is equal or larger than the given key, starting from the given page. This method returns the path.
        Type Parameters:
        K - key type
        V - value type
        Parameters:
        page - to start from as a root
        key - to search for, null means search for the first available key
        reverse - true if traversal is in reverse direction, false otherwise
        Returns:
        CursorPos representing path from the entry found, or from insertion point if not, all the way up to to the root page provided
      • upperBound

        private static <K,​V> int upperBound​(Page<K,​V> page)