UNPKG

@thi.ng/associative

Version:

ES Map/Set-compatible implementations with customizable equality semantics & supporting operations

60 lines 2.28 kB
import type { Fn3, Maybe, Pair } from "@thi.ng/api"; import type { EquivSetOpts, IEquivSet } from "./api.js"; /** * Similar to {@link ArraySet}, this class is an alternative implementation of * the native ES6 Set API using a * [`DCons`](https://docs.thi.ng/umbrella/dcons/classes/DCons.html) linked list * as backing store and a customizable value equality / equivalence predicate. * By the default uses * [`equiv`](https://docs.thi.ng/umbrella/equiv/functions/equiv.html) for * equivalence checking. * * Additionally, the type also implements the * [`ICopy`](https://docs.thi.ng/umbrella/api/interfaces/ICopy.html), * [`IEmpty`](https://docs.thi.ng/umbrella/api/interfaces/IEmpty.html) and * [`IEquiv`](https://docs.thi.ng/umbrella/api/interfaces/IEquiv.html) * interfaces itself. */ export declare class LLSet<T> extends Set<T> implements IEquivSet<T> { #private; constructor(vals?: Iterable<T> | null, opts?: Partial<EquivSetOpts<T>>); [Symbol.iterator](): SetIterator<T>; [Symbol.dispose](): void; get [Symbol.species](): typeof LLSet; get [Symbol.toStringTag](): string; get size(): number; copy(): LLSet<T>; empty(): LLSet<T>; clear(): void; first(): Maybe<T>; add(key: T): this; into(keys: Iterable<T>): this; has(key: T): boolean; /** * Returns the canonical (stored) value for `key`, if present. If * the set contains no equivalent for `key`, returns `notFound`. * * @param key - search key * @param notFound - default value */ get(key: T, notFound?: T): Maybe<T>; delete(key: T): boolean; disj(keys: Iterable<T>): this; equiv(o: any): boolean; /** * The value args given to the callback `fn` MUST be treated as * readonly/immutable. This could be enforced via TS, but would * break ES6 Set interface contract. * * @param fn - * @param thisArg - */ forEach(fn: Fn3<T, T, Set<T>, void>, thisArg?: any): void; entries(): SetIterator<Pair<T, T>>; keys(): SetIterator<T>; values(): SetIterator<T>; opts(): EquivSetOpts<T>; toString(): string; } export declare const defLLSet: <T>(vals?: Iterable<T> | null, opts?: Partial<EquivSetOpts<T>>) => LLSet<T>; //# sourceMappingURL=ll-set.d.ts.map