//#region src/keyedSet.d.ts /** * A Set implementation that uses a custom key function to determine uniqueness. * Items with the same key are considered equal, and adding a duplicate replaces * the existing item. * * @example * const set = new KeyedSet<{ id: number; name: string }, number>( * (item) => item.id, * ); * set.add({ id: 1, name: 'one' }); * set.add({ id: 1, name: 'replaced' }); // replaces previous item * set.getByKey(1); // { id: 1, name: 'replaced' } * * @template T - The type of items stored in the set * @template K - The type of the key extracted from items */ declare class KeyedSet { private map; private getKey; /** * @param getKey - Function to extract a unique key from each item * @param iterable - Optional initial items to add to the set */ constructor(getKey: (item: T) => K, iterable?: Iterable); /** The number of items in the set */ get size(): number; /** * Adds an item to the set. If an item with the same key exists, it will be * replaced. */ add(item: T): this; /** Adds multiple items to the set. */ addMultiple(items: Iterable): this; /** Checks if an item with the same key exists in the set. */ has(item: T): boolean; /** Checks if an item with the given key exists in the set. */ hasKey(key: K): boolean; /** Gets an item by its key, or undefined if not found. */ getByKey(key: K): T | undefined; /** * Removes an item from the set by computing its key. Returns true if the item * was removed. */ delete(item: T): boolean; /** Removes an item by its key. Returns true if the item was removed. */ deleteByKey(key: K): boolean; /** Removes multiple items from the set. Returns the number of items removed. */ deleteMultiple(items: Iterable): number; /** Removes multiple items by their keys. Returns the number of items removed. */ deleteMultipleByKeys(keys: Iterable): number; /** Removes all items from the set. */ clear(): void; /** Executes a callback for each item in the set. */ forEach(callback: (value: T, value2: T, set: KeyedSet) => void, thisArg?: unknown): void; values(): IterableIterator; keys(): IterableIterator; entries(): IterableIterator<[T, T]>; [Symbol.iterator](): IterableIterator; /** Returns all items as an array. */ toArray(): T[]; } /** * A Set that compares items by value instead of reference. Uses * `getCompositeKey` to generate a stable string key for any value. * * @example * const set = new ValueSet<{ x: number; y: number }>(); * set.add({ x: 1, y: 2 }); * set.add({ x: 1, y: 2 }); // ignored, same value already exists * set.size; // 1 */ declare class CompositeKeySet extends KeyedSet { constructor(iterable?: Iterable); } //#endregion export { CompositeKeySet, KeyedSet };