Class Container<T>

  • Type Parameters:
    T - Type of object to be scored and retrieved.
    All Implemented Interfaces:
    java.lang.Iterable<T>
    Direct Known Subclasses:
    DocArray

    public abstract class Container<T>
    extends java.lang.Object
    implements java.lang.Iterable<T>
    Base class to contain, rank and retrieve top K objects based on their score. This implementation use a modified version of the Quickselect algorithm.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected T[] arr  
    • Constructor Summary

      Constructors 
      Constructor Description
      Container​(int maxSize)  
      Container​(int maxSize, java.util.function.Supplier<T> sentinelObjectSupplier)  
      Container​(T[] arr)  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(T element)  
      abstract void calculateScore​(T target)  
      void clear()
      Removes all entries from the Container.
      T get​(int index)  
      protected java.lang.Object[] getArray()  
      T insertWithOverflow​(T element)  
      java.util.Iterator<T> iterator()  
      protected abstract boolean lessThan​(T a, T b)  
      protected void orderStatistic​(int start, int end, int i)  
      protected int partition​(int start, int end)  
      protected int pivotScheme​(int start, int end)  
      T pop()  
      void pullTopK​(int k, boolean ordered, boolean trim)  
      protected void quicksort​(int start, int end)  
      boolean remove​(T element)  
      int size()
      Returns the number of elements currently stored in the Container.
      protected void swap​(int a, int b)  
      T top()  
      • Methods inherited from class java.lang.Object

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

        forEach, spliterator
    • Field Detail

      • arr

        protected T[] arr
    • Constructor Detail

      • Container

        public Container​(int maxSize)
      • Container

        public Container​(int maxSize,
                         java.util.function.Supplier<T> sentinelObjectSupplier)
      • Container

        public Container​(T[] arr)
    • Method Detail

      • lessThan

        protected abstract boolean lessThan​(T a,
                                            T b)
      • calculateScore

        public abstract void calculateScore​(T target)
      • add

        public final void add​(T element)
      • get

        public final T get​(int index)
      • insertWithOverflow

        public T insertWithOverflow​(T element)
      • top

        public final T top()
      • pop

        public final T pop()
      • size

        public final int size()
        Returns the number of elements currently stored in the Container.
      • clear

        public final void clear()
        Removes all entries from the Container.
      • remove

        public final boolean remove​(T element)
      • pullTopK

        public void pullTopK​(int k,
                             boolean ordered,
                             boolean trim)
      • quicksort

        protected void quicksort​(int start,
                                 int end)
      • orderStatistic

        protected void orderStatistic​(int start,
                                      int end,
                                      int i)
      • pivotScheme

        protected int pivotScheme​(int start,
                                  int end)
      • partition

        protected int partition​(int start,
                                int end)
      • swap

        protected void swap​(int a,
                            int b)
      • getArray

        protected final java.lang.Object[] getArray()
      • iterator

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<T>