Typeberry by Fluffy Labs - v0.5.0
    Preparing search index...

    Class HashDictionary<K, V>

    Immutable view of the HashDictionary.

    Type Parameters

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Accessors

    • get size(): number

      Returns the number of entries in the dictionary.

      The count is derived from the auxiliary keyvals map, which stores all original key references and their associated values. This ensures that the size reflects the actual number of entries, independent of internal overrides in the main root structure.

      Returns number

      The total number of entries in the dictionary.

    Methods

    • Removes an entry with the specified key from the dictionary.

      Internally, this calls internalSet with undefined to mark the entry as deleted.

      Parameters

      • key: K

        The key of the entry to remove.

      Returns boolean

      true if an entry was removed (i.e. the key existed), otherwise false.

    • Returns an iterator over the [key, value] pairs in the dictionary.

      The iterator yields entries in insertion order.

      Returns Iterator<[K, V], any, any> & Iterable<[K, V], any, any>

      An iterator over [key, value] tuples for each entry in the dictionary.

    • Checks whether the dictionary contains an entry for the given key.

      ⚠️ Note: Avoid using has(...) together with get(...) in a pattern like this:

      if (dict.has(key)) {
      const value = dict.get(key);
      ...
      }

      This approach performs two lookups for the same key.

      Instead, prefer the following pattern, which retrieves the value once:

      const value = dict.get(key);
      if (value !== undefined) {
      ...
      }

      Parameters

      • key: K

        The key to check for.

      Returns boolean

      true if the dictionary contains an entry for the given key, otherwise false.

    • Adds a new entry to the dictionary or updates the value of an existing key.

      If an entry with the given key already exists, its value is replaced with the new one.

      Parameters

      • key: K

        The key to add or update in the dictionary.

      • value: V

        The value to associate with the specified key.

      Returns void

      Nothing (void).

    • Creates a new BlobDictionary initialized with the given entries.

      Type Parameters

      Parameters

      • entries: [K, V][]

        An array of [key, value] pairs used to populate the dictionary.

      • OptionalmapNodeThreshold: number

        The threshold that determines when the dictionary switches from using an array-based (ListChildren) node to a map-based (MapChildren) node for storing entries. Defaults to 0.

      Returns BlobDictionary<K, V>

      A new BlobDictionary containing the provided entries.