Class DoubleSortedList<T>

Type Parameters:
T - the type of elements contained in this list
All Implemented Interfaces:
Serializable, Cloneable, Iterable<T>, Collection<T>, List<T>, RandomAccess, SequencedCollection<T>

public class DoubleSortedList<T> extends SortedList<T>
Represents a sorted list of elements ordered by double keys. This implementation enhances performance by leveraging an array of double keys for fast binary search operations, synchronized with the list of elements.

It is designed for scenarios where frequent search operations based on double key values are required, offering significantly faster search capabilities compared to traditional list searches.

Author:
Andrey Malykhanov
See Also:
  • Constructor Details

    • DoubleSortedList

      public DoubleSortedList(Function<T,Double> doubleKeyExtractor)
      Creates a new DoubleSortedList using the provided key extractor to map elements to their double key values.
      Parameters:
      doubleKeyExtractor - A function that extracts the double key from elements of type T.
  • Method Details

    • getInsertionIndex

      public int getInsertionIndex(T element, boolean insertBefore)
      Description copied from class: SortedList
      Returns an index at which the given element can be inserted to preserve order of the elements in this list.
      Overrides:
      getInsertionIndex in class SortedList<T>
      Parameters:
      element - given element
      insertBefore - if true, the least possible index. If false, returns the greatest possible index
      Returns:
      index at which the given element can be inserted to preserve order of the elements in this list
    • getInsertionIndex

      public int getInsertionIndex(double key)
      Gets the index in the list where an element with the given key should be inserted. Assumes that the insertion must occur before the first found occurrence of the key, i.e. in the beginning of a series of the same keys, if any.
      Parameters:
      key - The key of the element.
      Returns:
      The index at which the element should be inserted.
    • getInsertionIndex

      public int getInsertionIndex(double key, boolean insertBefore)
      Gets the index in the list where an element with the given key should be inserted.
      Parameters:
      key - The key of the element.
      insertBefore - A flag indicating whether to insert before the first found occurrence (true) or after the last (false).
      Returns:
      The index at which the element should be inserted.
    • floor

      public T floor(double key)
    • floorWithIndex

      public Pair<T,Integer> floorWithIndex(double key)
    • ceiling

      public T ceiling(double key)
    • headList

      public List<T> headList(double key, boolean inclusive)
    • tailList

      public List<T> tailList(double key, boolean inclusive)
    • subList

      public List<T> subList(double beginKey, boolean inclusiveBegin, double endKey, boolean inclusiveEnd)
    • add

      public boolean add(T element)
      Specified by:
      add in interface Collection<T>
      Specified by:
      add in interface List<T>
      Overrides:
      add in class SortedList<T>
    • add

      public boolean add(T element, boolean insertBefore)
      Description copied from class: SortedList
      Adds the specified element to this list. Allows to specify where this element must be inserted in the case of several other element existing in this list that are equal to the one being inserted.
      Overrides:
      add in class SortedList<T>
      Parameters:
      element - the element being inserted
      insertBefore - if true the element will be inserted before all other elements that are equal to the element being inserted. Otherwise, the element will be inserted after all such elements
      Returns:
      true (as specified by Collection.add(E))
    • addAll

      public boolean addAll(Collection<? extends T> collection)
      Specified by:
      addAll in interface Collection<T>
      Specified by:
      addAll in interface List<T>
      Overrides:
      addAll in class SortedList<T>
    • add

      public void add(int index, T element)
      Specified by:
      add in interface List<T>
      Overrides:
      add in class ArrayList<T>
    • set

      public T set(int index, T element)
      Specified by:
      set in interface List<T>
      Overrides:
      set in class SortedList<T>
    • remove

      public boolean remove(Object element)
      Specified by:
      remove in interface Collection<T>
      Specified by:
      remove in interface List<T>
      Overrides:
      remove in class ArrayList<T>
    • remove

      public T remove(int index)
      Specified by:
      remove in interface List<T>
      Overrides:
      remove in class ArrayList<T>
    • removeAll

      public boolean removeAll(Collection<?> c)
      Specified by:
      removeAll in interface Collection<T>
      Specified by:
      removeAll in interface List<T>
      Overrides:
      removeAll in class ArrayList<T>
    • removeIf

      public boolean removeIf(Predicate<? super T> filter)
      Specified by:
      removeIf in interface Collection<T>
      Overrides:
      removeIf in class ArrayList<T>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<T>
      Specified by:
      clear in interface List<T>
      Overrides:
      clear in class ArrayList<T>
    • copy

      public DoubleSortedList<T> copy(UnaryOperator<T> copier)