Class RandomAccessIndexerBackend<T>

java.lang.Object
ai.timefold.solver.core.impl.bavet.common.index.RandomAccessIndexerBackend<T>
Type Parameters:
T - the type of tuple being indexed
All Implemented Interfaces:
Indexer<T>, IndexerBackend<T>

@NullMarked public final class RandomAccessIndexerBackend<T> extends Object implements IndexerBackend<T>
An IndexerBackend that supports random access to its entries. It is shown to be 10-20 % slower than LinkedListIndexerBackend in the micro benchmarks when used as the backend for constraint streams.
  • Constructor Details

    • RandomAccessIndexerBackend

      public RandomAccessIndexerBackend()
  • Method Details

    • put

      public ListEntry<T> put(Object compositeKey, T tuple)
      Description copied from interface: Indexer
      Modify operation.
      Specified by:
      put in interface Indexer<T>
      Parameters:
      compositeKey - modify composite key
      tuple - never null
      Returns:
      the entry to allow remove it from the index directly
    • remove

      public void remove(Object compositeKey, ListEntry<T> entry)
      Description copied from interface: Indexer
      Modify operation. Must not be called during Indexer.forEach(Object, Consumer) and invalidates any Indexer.iterator(Object) obtained before.
      Specified by:
      remove in interface Indexer<T>
      Parameters:
      compositeKey - modify composite key
      entry - never null
    • size

      public int size(Object compositeKey)
      Description copied from interface: Indexer
      Query operation.
      Specified by:
      size in interface Indexer<T>
      Parameters:
      compositeKey - query composite key
      Returns:
      at least 0
    • forEach

      public void forEach(Object compositeKey, Consumer<T> tupleConsumer)
      Description copied from interface: Indexer
      Query operation.
      Specified by:
      forEach in interface Indexer<T>
      Parameters:
      compositeKey - query composite key
      tupleConsumer - never null
    • iterator

      public Iterator<T> iterator(Object queryCompositeKey)
      Description copied from interface: Indexer
      Gets an iterator for the given composite key. The returned iterator does not support Iterator.remove().
      Specified by:
      iterator in interface Indexer<T>
      Parameters:
      queryCompositeKey - composite key uniquely identifying the backend or a set of backends
      Returns:
      possibly empty iterator for the given composite key
    • randomIterator

      public Iterator<T> randomIterator(Object queryCompositeKey, Random workingRandom)
      Description copied from interface: Indexer
      Iterator which picks elements randomly. Selection probability is uniform over all elements for the given composite key. By calling Iterator.remove(), the element is removed never to be returned again by this iterator. However, it is not removed from the index itself; the only way to remove from the index is to call Indexer.remove(Object, ListEntry), which will make any existing iterators invalid.
      Specified by:
      randomIterator in interface Indexer<T>
      Parameters:
      queryCompositeKey - composite key uniquely identifying the backend or a set of backends
      workingRandom - used to pick random elements
      Returns:
      iterator for the given composite key, possibly empty
    • randomIterator

      public Iterator<T> randomIterator(Object queryCompositeKey, Random workingRandom, Predicate<T> filter)
      Description copied from interface: Indexer
      As defined by Indexer.randomIterator(Object, Random), but only returning elements matching the given filter.
      Specified by:
      randomIterator in interface Indexer<T>
    • isRemovable

      public boolean isRemovable()
      Description copied from interface: Indexer
      Some indexers can be empty (size 0 and an empty forEach for all keys) but not yet removable.
      Specified by:
      isRemovable in interface Indexer<T>
      Returns:
      true if empty and all put() calls had a remove() call
    • toString

      public String toString()
      Overrides:
      toString in class Object