Class default<K, V>

Map uses same-value-zero equality for keys, which makes it more difficult to use reference types like buffers.

HashMap is very similar to Map, but accepts a hash function for keys. This function should return a primitive, such as a number or string, which will be used as the key.

It doesn't contain all the functionality of Map because we don't need it, but it should be fairly easy to update as needed.

const join = (arr) => arr.join(' ')

const map = new HashMap(join)

map.set([1, 2], 3)
map.get([1, 2])
// => 3

Type Parameters

  • K
  • V

Constructors

Accessors

Methods

Constructors

  • Type Parameters

    • K
    • V extends unknown

    Parameters

    • hash: ((key: K) => Primitive)
        • (key): Primitive
        • Parameters

          • key: K

          Returns Primitive

    • Optionaliterable: Iterable<[K, V], any, any> = []

    Returns default<K, V>

Accessors

  • get size(): number
  • Returns number

Methods

  • Parameters

    • key: K

      The key to remove.

    Returns boolean

    true if the key was present and removed, false otherwise.

  • Parameters

    • key: K

      The key to look up.

    Returns undefined | V

    The element associated with key, or undefined if it's not present.

  • Parameters

    • key: K

      The key to look up.

    Returns boolean

    true if key is present in the map, false otherwise.

  • Parameters

    • key: K

      The key to update.

    • value: V

      The value to add at key.

    Returns default<K, V>

    The map.

  • Returns IterableIterator<V, any, any>