UNPKG

@d1g1tal/collections

Version:
81 lines (79 loc) 4.01 kB
/** A {@link Map} that can contain multiple, unique, values for the same key. */ declare class SetMultiMap<K, V> extends Map<K, Set<V>> { /** * Adds a new element with a specified key and value to the SetMultiMap. * If an element with the same key already exists, the value will be added to the underlying {@link Set}. * If the value already exists in the {@link Set}, it will not be added again. * * @param key - The key to set. * @param value - The value to add to the SetMultiMap. * @returns The SetMultiMap with the updated key and value. */ set(key: K, value: V): this; /** * Adds a new Set with a specified key and value to the SetMultiMap. * If an element with the same key already exists, the value will be added to the underlying {@link Set}. * If the value already exists in the {@link Set}, it will not be added again. * * @param key - The key to set. * @param value - The set of values to add to the SetMultiMap. * @returns The SetMultiMap with the updated key and value. */ set(key: K, value: Set<V>): this; /** * Gets the value associated with the specified key. If the key does not exist, it will insert the default value and return it. * @param key The key to get the value for. * @param defaultValue The default value to insert if the key does not exist. * @returns The value associated with the specified key, or the default value if the key does not exist. */ getOrInsert(key: K, defaultValue: V): V; /** * Gets the value associated with the specified key. If the key does not exist, it will insert the default value and return it. * @param key The key to get the value for. * @param defaultValue The default value to insert if the key does not exist. * @returns The value associated with the specified key, or the default value if the key does not exist. */ getOrInsert(key: K, defaultValue: Set<V>): Set<V>; /** * Gets the value associated with the specified key. If the key does not exist, it will compute the value using the provided function, insert it, and return it. * @param key The key to get the value for. * @param compute The function to compute the value if the key does not exist. * @returns The value associated with the specified key, or the computed value if the key does not exist. */ getOrInsertComputed(key: K, compute: (key: K) => V): V; /** * Gets the value associated with the specified key. If the key does not exist, it will compute the value using the provided function, insert it, and return it. * @param key The key to get the value for. * @param compute The function to compute the value if the key does not exist. * @returns The value associated with the specified key, or the computed value if the key does not exist. */ getOrInsertComputed(key: K, compute: (key: K) => Set<V>): Set<V>; /** * Finds a specific value for a specific key using an iterator function. * @param key The key to find the value for. * @param iterator The iterator function to use to find the value. * @returns The value for the specified key */ find(key: K, iterator: (value: V) => boolean): V | undefined; /** * Checks if a specific key has a specific value. * * @param key The key to check. * @param value The value to check. * @returns True if the key has the value, false otherwise. */ hasValue(key: K, value: V): boolean; /** * Removes a specific value from a specific key. * @param key The key to remove the value from. * @param value The value to remove. * @returns True if the value was removed, false otherwise. */ deleteValue(key: K, value: V | undefined): boolean; /** * The string tag of the SetMultiMap. * @returns The string tag of the SetMultiMap. */ get [Symbol.toStringTag](): string; } export { SetMultiMap };