Class ReverseOffsetLookupCache<VALUE_TYPE,EXTRA_INPUT_TYPE>
java.lang.Object
com.illumon.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
ConstructorsConstructorDescriptionReverseOffsetLookupCache(OffsetLookup<VALUE_TYPE, EXTRA_INPUT_TYPE> lookupFunction) -
Method Summary
Modifier and TypeMethodDescriptionintapplyAsInt(VALUE_TYPE value) Get the index of value in reverse lookup cache.voidclear()Release all resources held by the cache.voidensurePopulated(int highestIndexNeeded, Supplier<EXTRA_INPUT_TYPE> extraFactory, Consumer<EXTRA_INPUT_TYPE> extraCleanup) Ensure that the cache is populated for allindexes <= highestIndexNeeded.
-
Constructor Details
-
ReverseOffsetLookupCache
-
-
Method Details
-
ensurePopulated
public 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.- 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:
applyAsIntin 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.
-