Class FastAccessNumberMap<T>

  • Type Parameters:
    T - type of objects to store in this map
    All Implemented Interfaces:
    Iterable<T>

    public class FastAccessNumberMap<T>
    extends Object
    implements Iterable<T>
    A map from long to T. Gives O(1) access to indexes that are between 0 and pageSize*maxPageCount at the cost of high memory use. Values are kept in dynamically allocated pages, each of a fixed size.

    It can be thought of as a big array that is split up into pages of a fixed size. This is useful if you want to use a sparse set of indexes since you don't have to allocate the full array immediately. If you are going to fill all indexes then it is more practical to use a normal array or list.

    If you try to access an index outside of the max page count then an overflow hash map is used as a fallback mechanism. In that case access will be slower than O(1).

    • Constructor Detail

      • FastAccessNumberMap

        public FastAccessNumberMap()
        Constructs a map with O(1) access up to approximately index 5000.
      • FastAccessNumberMap

        public FastAccessNumberMap​(int expectedSize)
        Constructs a map with O(1) access up to index expectedSize.
        Parameters:
        expectedSize - - the maximum number of elements expected to be inserted into the map before overflowing to slower storage.
      • FastAccessNumberMap

        public FastAccessNumberMap​(int pageSize,
                                   int maxPageCount)
        Constructs a map with O(1) access up to index pageSize*maxPageCount.
        Parameters:
        pageSize - page size
        maxPageCount - max page count
    • Method Detail

      • get

        public T get​(long index)
        Get the value at an index.
        Parameters:
        index - value index
        Returns:
        value at index
      • put

        public void put​(long index,
                        T value)
        Store a value at an index.
        Parameters:
        index - value index
        value - value to store