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

    Class BlobDictionary<K, V>

    A map which uses byte blobs as keys

    Type Parameters

    Hierarchy (View Summary)

    Index

    Constructors

    • Protected constructor used internally by BlobDictionary.new and BlobDictionary.fromEntries.

      This enforces controlled instantiation — users should create instances through the provided static factory methods instead of calling the constructor directly.

      Type Parameters

      Parameters

      • mapNodeThreshold: 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.

      Returns BlobDictionary<K, V>

    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

    • Default iterator for the dictionary.

      Equivalent to calling entries. Enables iteration with for...of:

      for (const [key, value] of dict) {
      ...
      }

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

      An iterator over [key, value] pairs.

    • 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.

    • Retrieves the value associated with the given key from the dictionary.

      If the key does not exist, this method returns undefined.

      Parameters

      • key: K

        The key whose associated value should be retrieved.

      Returns V | undefined

      The value associated with the specified key, or undefined if the key is not present.

    • 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.

    • Returns an iterator over the keys in the dictionary.

      The iterator yields each key in insertion order.

      Returns Iterator<K, any, any> & Iterable<K, any, any>

      An iterator over all keys in the dictionary.

    • 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 sorted array of values, ordered by their corresponding keys.

      Iterates over all entries in the dictionary and sorts them according to the provided comparator function applied to the keys.

      Parameters

      • comparator: Comparator<K>

        A comparator function that can compare two keys.

      Returns V[]

      A new array containing all values from the dictionary, sorted according to their keys.

    • Returns an iterator over the values in the dictionary.

      The iterator yields each value in insertion order.

      Returns Iterator<V, any, any> & Iterable<V, any, any>

      An iterator over all values in the dictionary.

    • 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.