An index that uses native JavaScript objects to efficiently store and retrieve arbitrary values.

This container only works with hashable JavaScript types, such as string or number. Types that cannot be used as the key in a plain JavaScript object will not work.

Type Parameters

  • T
  • K extends PropertyKey = T & PropertyKey

Implements

Constructors

Properties

areKeysEqual: (a: K, b: K) => boolean
getKey: (element: T) => K
isEqual: (a: T, b: T) => boolean
onDuplicateElements: ResolveAction
onDuplicateKeys: ResolveAction

Accessors

  • get size(): number
  • Experimental

    Count the amount of elements in the collection.

    ⚠️ In most cases, this should be an O(1) operation. However, there are cases where this can be an O(n) operation. Therefore, it is recommended to always cache the result in a local variable.

    Returns number

Methods

  • Experimental

    Add an element to the collection. If the element already exists, update its value.

    The location where the element is placed depends on the collection type, and in the generic case there is no guarantee on the location where it is inserted.

    This method returns a pair with the first element indicating whether the element was added, while the second element refers to the actual location of the element.

    Parameters

    • element: T

    Returns AddResult<T>

  • Experimental

    Remove all elements from this collection, effectively setting the collection to the empty collection.

    Returns void

  • Experimental

    Returns Generator<NativeIndexCursor<T, K>, void, unknown>

  • Experimental

    Remove an element from the collection. If multiple elements are matched, the collection picks one of them.

    Parameters

    • element: T

    Returns boolean

    true if the element was found, false otherwise.

  • Experimental

    Remove an element from the collection. If multiple elements are matched, the collection removes all of them.

    Parameters

    • element: T

    Returns number

    The amount of elements that was removed.

  • Experimental

    Remove the element pointed to by the iterator result from this collection.

    Parameters

    • position: NativeIndexCursor<T, K>

    Returns void

  • Experimental

    Delete a pair from the underlying collection that has the given key as key.

    Returns the amount of items that have been deleted.

    Parameters

    • key: K

    Returns number

  • Experimental

    Similar to Dict.getValue, except that it returns the pair that was inserted in the collection.

    Parameters

    • key: K

    Returns undefined | NativeIndexCursor<T, K>

  • Experimental

    Checks if the collection holds the given element.

    Parameters

    • element: T

      The element to check membership of.

    Returns boolean

    True if the collections holds the given element, false otherwise.

  • Experimental

    Checks whether there a pair in this collection that has the given key.

    Parameters

    • key: K

    Returns boolean