UNPKG

thorish

Version:

This is a library of useful JS concepts and data structures for Node and the browser. It it, unashamedly, a dumping ground for code needed by [@samthor](https://twitter.com/samthor)'s projects.

138 lines (137 loc) 3.71 kB
/** * A set which allows the same value to be added many times. */ export declare class CountSet<T> { private readonly m; private count; /** * The total number of values (aka, the number of calls to {@link CountSetprivate add}). */ total(): number; add(t: T): boolean; entries(): MapIterator<[T, number]>; delete(t: T): boolean; has(t: T): boolean; uniques(): MapIterator<T>; keys(): IterableIterator<T>; } /** * A set of pairs. Adding one side (e.g., `.add(a, b)`) is the same as adding the other (e.g., * `.add(b, a)`). */ export declare class PairSet<K> { private readonly m; size(): number; add(a: K, b: K): boolean; delete(a: K, b: K): boolean; has(a: K, b: K): boolean; hasAny(k: K): boolean; otherKeys(k: K): IterableIterator<K>; pairsWith(k: K): number; keys(): IterableIterator<K>; pairs(): IterableIterator<[K, K]>; clear(): void; } /** * A map with a pair of keys. Both sides are added at once. */ export declare class PairMap<K, V> { private readonly m; private implicitGet; set(a: K, b: K, v: V): boolean; size(): number; pairsWith(k: K): number; otherKeys(k: K): IterableIterator<K>; otherEntries(k: K): IterableIterator<[K, V]>; pairs(): IterableIterator<[K, K]>; pairsEntries(): IterableIterator<[K, K, V]>; delete(a: K, b: K): boolean; has(a: K, b: K): boolean; hasAny(k: K): boolean; get(a: K, b: K): V | undefined; keys(): IterableIterator<K>; clear(): void; } /** * A map which itself contains a set of items. Each key may have multiple items set. */ export declare class MultiMap<K, V> { private readonly m; private _totalSize; add(k: K, v: V): boolean; /** * Clears all values for this key. */ clearKey(k: K): boolean; /** * Delete a specific key/value combination. */ delete(k: K, v: V): boolean; has(k: K, v: V): boolean; get(k: K): Iterable<V>; /** * Returns the count of values for this key. */ count(k: K): number; /** * Returns the size of this map; the number of keys with valid values. * * This is not the total number of values. */ get size(): number; /** * Returns the total number of values set for all keys. */ get totalSize(): number; /** * Iterates through all active keys (with any values). */ keys(): Iterable<K>; clear(): void; } export declare class BiMap<A, B> { private readonly fwd; private readonly rwd; private constructor(); get size(): number; clear(): void; keys(): MapIterator<A>; values(): MapIterator<B>; entries(): MapIterator<[A, B]>; invert(): BiMap<B, A>; set(a: A, b: B): this; has(a: A): boolean; hasFar(b: B): boolean; get(a: A): B | undefined; getFar(b: B): A | undefined; delete(a: A): boolean; deleteFar(b: B): boolean; static create<A, B>(): BiMap<A, B>; } export declare class TransformMap<K, V, T = V> { private readonly data; private readonly defaultValue; private readonly transform; constructor(defaultValue: V, transform: (value: V, withValue: T) => V); /** * Deletes the given key. Basically reverts it to its default value. */ delete(k: K): boolean; /** * Update the given key. */ update(k: K, update: T): V; /** * Return the current value for this key, or the default. */ get(k: K): V; /** * Return all keys for non-default values. */ keys(): IterableIterator<K>; /** * Whether this key has a non-default value. */ has(k: K): boolean; clear(): void; }