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.
115 lines (114 loc) • 3.05 kB
TypeScript
/**
* A set which allows the same value to be added many times.
*/
export declare class CountSet<T> {
private 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 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]>;
}
/**
* A map with a pair of keys. Both sides are added at once.
*/
export declare class PairMap<K, V> {
private 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>;
}
/**
* A map which itself contains a set of items. Each key may have multiple items set.
*/
export declare class MultiMap<K, V> {
private 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>;
}
export declare class TransformMap<K, V, T = V> {
private data;
private defaultValue;
private 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;
}