Class ReverseOffsetLookupCache<VALUE_TYPE,EXTRA_INPUT_TYPE>
java.lang.Object
io.deephaven.util.datastructures.cache.ReverseOffsetLookupCache<VALUE_TYPE,EXTRA_INPUT_TYPE>
- All Implemented Interfaces:
ToIntFunction<VALUE_TYPE>
public class ReverseOffsetLookupCache<VALUE_TYPE,EXTRA_INPUT_TYPE>
extends Object
implements ToIntFunction<VALUE_TYPE>
Caching data structure interface for caching Object to int (offset) mappings returned by an expensive, idempotent
lookup function from int to Object.
-
Constructor Summary
ConstructorDescriptionReverseOffsetLookupCache
(@NotNull OffsetLookup<VALUE_TYPE, EXTRA_INPUT_TYPE> lookupFunction) -
Method Summary
Modifier and TypeMethodDescriptionint
applyAsInt
(VALUE_TYPE value) Get the index of value in reverse lookup cache.void
clear()
Release all resources held by the cache.void
ensurePopulated
(int highestIndexNeeded, @NotNull Supplier<EXTRA_INPUT_TYPE> extraFactory, @Nullable Consumer<EXTRA_INPUT_TYPE> extraCleanup) Ensure that the cache is populated for allindexes <= highestIndexNeeded
.
-
Constructor Details
-
ReverseOffsetLookupCache
public ReverseOffsetLookupCache(@NotNull @NotNull OffsetLookup<VALUE_TYPE, EXTRA_INPUT_TYPE> lookupFunction)
-
-
Method Details
-
ensurePopulated
public void ensurePopulated(int highestIndexNeeded, @NotNull @NotNull Supplier<EXTRA_INPUT_TYPE> extraFactory, @Nullable @Nullable Consumer<EXTRA_INPUT_TYPE> extraCleanup) Ensure that the cache is populated for allindexes <= highestIndexNeeded
.- Parameters:
highestIndexNeeded
- The highest index needed for this operation
-
applyAsInt
Get the index of value in reverse lookup cache. Be sure to callensurePopulated(int, Supplier, Consumer)
for the appropriate index bound, first.- Specified by:
applyAsInt
in interfaceToIntFunction<VALUE_TYPE>
- Parameters:
value
- The value to look up- Returns:
- The index of value in the cache, or
NULL_INDEX
(-1) if not found
-
clear
public void clear()Release all resources held by the cache.
-