UNPKG

@d1g1tal/collections

Version:
78 lines (76 loc) 3.83 kB
import { List } from './list.js'; /** A {@link Map} that can contain multiple values for the same key */ declare class MultiMap<K, V> extends Map<K, List<V>> { /** * Adds a new element with a specified key and value to the MultiMap. * If an element with the same key already exists, the value will be added to the underlying {@link List}. * @param key - The key to set. * @param value - The value to add to the MultiMap. * @returns The MultiMap with the updated key and value. */ set(key: K, value: V): this; /** * Adds a new List with a specified key and value to the MultiMap. * If an element with the same key already exists, the value will be added to the underlying {@link List}. * @param key The key to set. * @param value The list of values to add to the MultiMap. * @returns The MultiMap with the updated key and value. */ set(key: K, value: List<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: List<V>): List<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) => List<V>): List<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; /** * Gets the string tag for the class * @returns The string tag of the class */ get [Symbol.toStringTag](): string; } export { MultiMap };