UNPKG

@thi.ng/sorted-map

Version:

Skiplist-based sorted map & set implementation

62 lines 2.73 kB
import type { Fn3, ICompare, Maybe, Pair } from "@thi.ng/api"; import type { IEquivSet } from "@thi.ng/associative"; import type { IReducible, Reduced, ReductionFn } from "@thi.ng/transducers"; import type { SortedSetOpts } from "./api.js"; /** * Sorted set implementation with standard ES6 Set API, customizable value * equality and comparison semantics and additional functionality: * * - range queries (via {@link SortedSet.entries}, {@link SortedSet.keys}, * {@link SortedSet.values}) * - multiple value addition/deletion via {@link SortedSet.into} and * {@link SortedSet.disj} * * Furthermore, this class implements the * [`ICopy`](https://docs.thi.ng/umbrella/api/interfaces/ICopy.html), * [`ICompare`](https://docs.thi.ng/umbrella/api/interfaces/ICompare.html), * [`IEmpty`](https://docs.thi.ng/umbrella/api/interfaces/IEmpty.html) and * [`IEquiv`](https://docs.thi.ng/umbrella/api/interfaces/IEquiv.html) * interfaces defined by [`thi.ng/api`](https://thi.ng/api). The latter two * allow instances to be used as keys themselves in other data types defined in * this (and other) package(s). * * This set uses a {@link SortedMap} as backing store and therefore has the same * resizing characteristics. */ export declare class SortedSet<T> extends Set<T> implements IEquivSet<T>, ICompare<Set<T>>, IReducible<T, any> { #private; /** * Creates new instance with optional given values and/or * implementation options. The options are the same as used by * {@link SortedMap}. * * @param values - input values * @param opts - config options */ constructor(values?: Iterable<T> | null, opts?: Partial<SortedSetOpts<T>>); [Symbol.iterator](): SetIterator<T>; [Symbol.dispose](): void; get [Symbol.species](): typeof SortedSet; get [Symbol.toStringTag](): string; get size(): number; copy(): SortedSet<T>; empty(): SortedSet<T>; compare(o: Set<T>): number; equiv(o: any): boolean; $reduce<R>(rfn: ReductionFn<T, any>, acc: R | Reduced<R>): R | Reduced<R>; entries(key?: T, max?: boolean): SetIterator<Pair<T, T>>; keys(key?: T, max?: boolean): SetIterator<T>; values(key?: T, max?: boolean): SetIterator<T>; add(key: T): this; into(keys: Iterable<T>): this; clear(): void; first(): Maybe<T>; delete(key: T): boolean; disj(keys: Iterable<T>): this; forEach(fn: Fn3<Readonly<T>, Readonly<T>, Set<T>, void>, thisArg?: any): void; has(key: T): boolean; get(key: T, notFound?: T): Maybe<T>; opts(): SortedSetOpts<T>; } export declare const defSortedSet: <T>(vals?: Iterable<T> | null, opts?: Partial<SortedSetOpts<T>>) => SortedSet<T>; //# sourceMappingURL=sorted-set.d.ts.map