CmpStr - v3.2.1
    Preparing search index...

    Class HashTable<K, T>

    HashTable class implements an instantiable hash table/cache. Allows for multiple independent caches with type safety and high performance.

    Type Parameters

    • K extends string

      The type of the label for the key (e.g. string, MetricName, …)

    • T

      The type of value to be stored in the hash table (e.g. MetricCompute, string, …)

    Index

    Constructors

    • Creates an instance of HashTable.

      Type Parameters

      • K extends string

        The type of the label for the key (e.g. string, MetricName, …)

      • T

        The type of value to be stored in the hash table (e.g. MetricCompute, string, …)

      Parameters

      • OptionalLRU: boolean = true

        Whether to use Least Recently Used (LRU) eviction policy

      Returns HashTable<K, T>

    Properties

    LRU: boolean = true

    Whether to use Least Recently Used (LRU) eviction policy

    table: Map<string, T> = ...

    The internal map to store entries. The key is a string generated from the label and any number of hashed strings. The value is of type T.

    MAX_LEN: number = 2048

    The max. length of a string to hash, which is set to 2048 characters

    TABLE_SIZE: number = 10_000

    The max. size of the hash table, which is set to 10,000

    Methods

    • Clears the hash table. This method removes all entries from the hash table.

      Returns void

    • Deletes an entry from the hash table by its key.

      Parameters

      • key: string

        The key of the entry to delete

      Returns boolean

      • True if the entry was deleted, false if the key was not found
    • Retrieves the entry from the hash table by its key.

      Parameters

      • key: string

        The key to look up

      Returns T | undefined

      • The entry if found, undefined otherwise
    • Checks if a key exists in the hash table.

      Parameters

      • key: string

        The key to check

      Returns boolean

      • True if the key exists, false otherwise
    • Generates a unique hash key for any number of string arguments. Return false if any string exceeds the maximum length. The key is in the format "label-H1-H2-H3-..."

      Parameters

      • label: K

        Label for this key (e.g. metric name, normalization flags, …)

      • strs: string[]

        Array of strings to hash (e.g. input, params, …)

      • Optionalsorted: boolean = false

        Whether to sort the hashes before creating the key

      Returns string | false

      • A unique hash key or false if any string is too long
    • Adds an entry to the hash table. If the table is full, it evicts the least recently used entry (if LRU is enabled).

      Parameters

      • key: string

        The hashed key for the entry

      • entry: T

        The entry itself to add

      • Optionalupdate: boolean = true

        Whether to update the entry if it already exists

      Returns boolean

      • True if added successfully, false if the table is full
    • Returns the current size of the hash table.

      Returns number

      • The number of entries in the hash table