Interface SortedIndex<V extends SortedIndex.IndexEntry>

  • Type Parameters:
    V - The type of the IndexEntries.
    All Known Implementing Classes:
    AvlTreeIndex, RedBlackTreeIndex

    public interface SortedIndex<V extends SortedIndex.IndexEntry>
    Defines an Index that orders its IndexEntries by an Int64 (long) Key.

    Notes:

    • Implementations of this interface are not necessarily thread-safe and no assumptions should be made about multi-thread consistency.
    • No implementation of this class should be able to index null values. As such, for all the retrieval methods, a null value can be safely interpreted as no result found.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  SortedIndex.IndexEntry
      Defines a generic entry into an Index.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void clear()
      Clears the contents of the Index.
      void forEach​(java.util.function.Consumer<V> consumer)
      Iterates through each item in the Index, in natural order, and calls the given consumer on all of them.
      V get​(long key)
      Gets an item with the given key.
      V getCeiling​(long key)
      Gets the smallest item whose key is greater than or equal to the given key.
      V getFirst()
      Gets the smallest item in the index.
      V getFloor​(long key)
      Gets the largest item whose key is smaller than or equal to the given key.
      V getLast()
      Gets the largest item in the index.
      V put​(V item)
      Inserts the given item into the Index.
      V remove​(long key)
      Removes any item with the given key from the Index.
      int size()
      Gets a value indicating the number of items in the Index.
    • Method Detail

      • clear

        void clear()
        Clears the contents of the Index.
      • put

        V put​(V item)
        Inserts the given item into the Index. If there already exists an item with the same key, it will be overridden.
        Parameters:
        item - The item to insert.
        Returns:
        The displaced item, if any.
      • remove

        V remove​(long key)
        Removes any item with the given key from the Index.
        Parameters:
        key - The key of the item to remove.
        Returns:
        The removed item, or null if nothing was removed.
      • size

        int size()
        Gets a value indicating the number of items in the Index.
        Returns:
        Integer indicating the size or number of items in the Index.
      • get

        V get​(long key)
        Gets an item with the given key.
        Parameters:
        key - The key to search by.
        Returns:
        The requested item, if it exists, or null if it doesn't.
      • getCeiling

        V getCeiling​(long key)
        Gets the smallest item whose key is greater than or equal to the given key.
        Parameters:
        key - the Key to search by.
        Returns:
        The sought item, or null if it doesn't exist.
      • getFloor

        V getFloor​(long key)
        Gets the largest item whose key is smaller than or equal to the given key.
        Parameters:
        key - the Key to search by.
        Returns:
        The sought item, or null if it doesn't exist.
      • getFirst

        V getFirst()
        Gets the smallest item in the index.
        Returns:
        The sought item, or null (if no items in the index).
      • getLast

        V getLast()
        Gets the largest item in the index.
        Returns:
        The sought item, or null (if no items in the index).
      • forEach

        void forEach​(java.util.function.Consumer<V> consumer)
        Iterates through each item in the Index, in natural order, and calls the given consumer on all of them.
        Parameters:
        consumer - The consumer to invoke.
        Throws:
        java.util.ConcurrentModificationException - If the Index is modified while this method is executing.