@glideapps/ts-necessities
    Preparing search index...

    Class DefaultMap<K, V>

    A Map that returns default values for keys that are not present.

    To map strings to Sets of numbers, for example, DefaultMap can be used like this:

    const m = new DefaultMap<string, Set<number>>(() => new Set());
    m.get("foo"); // returns an empty `Set`
    m.get("bar").add(1);
    m.get("bar"); // returns a `Set` containing `1`.

    Type Parameters

    • K

      The key type.

    • V

      The value type.

    Hierarchy

    • Map<K, V>
      • DefaultMap

    Implements

    Index

    Constructors

    • Type Parameters

      • K
      • V

      Parameters

      • _defaultFunc: (k: K) => V

        Must return the default value for key k. Will only be called when necessary.

      • OptionalinitKVPs: readonly (readonly [K, V])[]

        An array of [key, value] arrays to initialize the map with.

      Returns DefaultMap<K, V>

    Properties

    "[toStringTag]": string
    size: number

    the number of elements in the Map.

    "[species]": MapConstructor

    Methods

    • Returns an iterable of entries in the map.

      Returns MapIterator<[K, V]>

    • Returns void

    • Parameters

      • key: K

      Returns boolean

      true if an element in the Map existed and has been removed, or false if the element does not exist.

    • Returns an iterable of key, value pairs for every entry in the map.

      Returns MapIterator<[K, V]>

    • Executes a provided function once per each key/value pair in the Map, in insertion order.

      Parameters

      • callbackfn: (value: V, key: K, map: Map<K, V>) => void
      • OptionalthisArg: any

      Returns void

    • Returns the value for k. If k is not present, creates the default value via [[_defaultFunc]], sets that default as the value for k and returns it.

      Parameters

      Returns V

    • Parameters

      • key: K

      Returns boolean

      boolean indicating whether an element with the specified key exists or not.

    • Returns an iterable of keys in the map

      Returns MapIterator<K>

    • Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.

      Parameters

      • key: K
      • value: V

      Returns this

    • Sets the value for k to f(v) where v is the previous value for k, or the default if not present. Returns the new value.

      These two lines are equivalent:

      m.set("foo", m.get("foo") + 1);
      m.update("foo", x => x + 1);

      Parameters

      • k: K
      • f: (v: V) => V

      Returns V

    • Returns an iterable of values in the map

      Returns MapIterator<V>