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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidQuery operation.booleanSome indexers can be empty (size 0 and an empty forEach for all keys) but not yet removable.Gets an iterator for the given composite key.Modify operation.randomIterator(Object queryCompositeKey, Random workingRandom) Iterator which picks elements randomly.randomIterator(Object queryCompositeKey, Random workingRandom, Predicate<T> filter) As defined byIndexer.randomIterator(Object, Random), but only returning elements matching the given filter.voidModify operation.intQuery operation.toString()
-
Constructor Details
-
RandomAccessIndexerBackend
public RandomAccessIndexerBackend()
-
-
Method Details
-
put
Description copied from interface:IndexerModify operation. -
remove
Description copied from interface:IndexerModify operation. Must not be called duringIndexer.forEach(Object, Consumer)and invalidates anyIndexer.iterator(Object)obtained before. -
size
Description copied from interface:IndexerQuery operation. -
forEach
Description copied from interface:IndexerQuery operation. -
iterator
Description copied from interface:IndexerGets an iterator for the given composite key. The returned iterator does not supportIterator.remove(). -
randomIterator
Description copied from interface:IndexerIterator which picks elements randomly. Selection probability is uniform over all elements for the given composite key. By callingIterator.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 callIndexer.remove(Object, ListEntry), which will make any existing iterators invalid.- Specified by:
randomIteratorin interfaceIndexer<T>- Parameters:
queryCompositeKey- composite key uniquely identifying the backend or a set of backendsworkingRandom- 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:IndexerAs defined byIndexer.randomIterator(Object, Random), but only returning elements matching the given filter.- Specified by:
randomIteratorin interfaceIndexer<T>
-
isRemovable
public boolean isRemovable()Description copied from interface:IndexerSome indexers can be empty (size 0 and an empty forEach for all keys) but not yet removable.- Specified by:
isRemovablein interfaceIndexer<T>- Returns:
- true if empty and all put() calls had a remove() call
-
toString
-