Class ReverseOffsetLookupCache<VALUE_TYPE,EXTRA_INPUT_TYPE>

All Implemented Interfaces:

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 Details

  • 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 all indexes <= highestIndexNeeded.
      highestIndexNeeded - The highest index needed for this operation
    • applyAsInt

      public int applyAsInt(VALUE_TYPE value)
      Get the index of value in reverse lookup cache. Be sure to call ensurePopulated(int, Supplier, Consumer) for the appropriate index bound, first.
      Specified by:
      applyAsInt in interface ToIntFunction<VALUE_TYPE>
      value - The value to look up
      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.