Class ArrayBasedLongIndex<T>

  • Type Parameters:
    T - type of stored values
    All Implemented Interfaces:
    LongIndex<T>

    public class ArrayBasedLongIndex<T>
    extends Object
    implements LongIndex<T>
    Thread-safe array-based LongIndex for non-negative long keys.

    Implemented as an array of arrays (chunks). When value is written or read by key, higher bits of the key give an index of a chunk, lower bits - an index inside a chunk.

    A size of the chunk is regulated by the chunkPower constructor parameter, chunkSize = 2^chunkPower. The larger a chunkPower, the bigger chunks are and the fewer chunks index have for the same number of elements.

    The upper bound for keys stored in the index is MAX_ARRAY_SIZE * chunkSize.

    • Constructor Detail

      • ArrayBasedLongIndex

        public ArrayBasedLongIndex()
      • ArrayBasedLongIndex

        public ArrayBasedLongIndex​(int chunkPower,
                                   boolean optimizeForRead)
        Parameters:
        chunkPower - number of lower bits specifying an index inside chunk, 0 <= chunkPower <= 30.
    • Method Detail

      • clear

        public void clear()
      • size

        public int size()
      • processAscending

        public void processAscending​(@NotNull
                                     LongIndexProcessor<T> p,
                                     long startKey)
      • processDescending

        public void processDescending​(@NotNull
                                      LongIndexProcessor<T> p,
                                      long startKey)
      • set

        public void set​(long key,
                        T value)
        Writes value for given key
        Specified by:
        set in interface LongIndex<T>
        Parameters:
        key - key of interest
        value - value to write
        Throws:
        IllegalArgumentException - if key is too large for this index
      • get

        @Nullable
        public T get​(long key)
        Returns value stored for given key. Returns null if key is too large for this index
        Specified by:
        get in interface LongIndex<T>
        Parameters:
        key - key of interest
        Returns:
        see above
      • optimizeForReadPerformance

        @NotNull
        public List<Integer> optimizeForReadPerformance​(long minId,
                                                        long maxId)
        Optimizes chunks corresponding to the specified ids range for read performance (irregadless of the max id, the last chunk will never be optimized)
        Returns:
        ids of optimized chunks