@twinfinity/core
    Preparing search index...

    Class IndexedMap<T>

    A simple map-like data structure that uses an array for storage. This class is not memory efficient for sparse lookups, as it uses an array internally and will allocate memory for all indices up to the highest key used. It is however very fast for lookups.

    It is not possible to store undefined values in this map, as undefined is used to represent keys that have not been set. This class is only intended to be used where the key is mostly a sequential number.

    Type Parameters

    • T
    Index

    Constructors

    Accessors

    Methods

    Constructors

    • Constructs a new IndexedMap.

      Type Parameters

      • T

      Parameters

      • initialCapacity: number = 0

        The initial capacity of the map. Defaults to 0.

      Returns IndexedMap<T>

    Accessors

    • get capacity(): number

      Gets the current capacity of the map. This is not the number of items stored in the map, but rather the size of the internal array.

      Returns number

      The current capacity of the map.

    Methods

    • Clears all items from the map. This is a heavy operation as it has to zero out the memory used by.

      Returns void

    • Gets the value for the given key.

      Parameters

      • key: number

        The key to get the value for.

      Returns undefined | T

      The value for the key, or undefined if the key does not exist.

    • Checks if the map contains the given key.

      Parameters

      • key: number

        The key to check for.

      Returns boolean

      true if the key exists in the map, otherwise false.

    • Sets the value for the given key.

      Parameters

      • key: number

        The key to set the value for.

      • value: T

        The value to set.

      Returns T

      The value that was set.