UNPKG

fp-search-algorithms

Version:

Functional Programming Style Search Algorithms and Unordered Containers

64 lines (63 loc) 1.99 kB
declare const ENTRY = 0; declare const ARRAY_NODE = 1; declare const INDEX_NODE = 2; declare const COLLISION_NODE = 3; /** @internal */ export type Node<K, V> = ArrayNode<K, V> | CollisionNode<K, V> | IndexNode<K, V>; type Entry<K, V> = { k: K; type: typeof ENTRY; v: V; }; type ArrayNode<K, V> = { array: (Entry<K, V> | Node<K, V> | undefined)[]; size: number; type: typeof ARRAY_NODE; }; /** @internal */ export type IndexNode<K, V> = { array: (Entry<K, V> | Node<K, V>)[]; bitmap: number; type: typeof INDEX_NODE; }; type CollisionNode<K, V> = { array: Entry<K, V>[]; hash: number; type: typeof COLLISION_NODE; }; type Flag = { val: boolean; }; /** @internal */ export declare const createEmptyNode: () => IndexNode<any, any>; /** * Mask the hash to get only the bucket corresponding to shift * @internal */ export declare function mask(hash: number, shift: number): number; /** * Set only the Nth bit where N is the masked hash * @internal */ export declare function bitpos(hash: number, shift: number): number; /** * Associate a node with a new entry, creating a new node * @internal */ export declare function assoc<K, V>(root: Node<K, V>, shift: number, hash: number, key: K, val: V, addedLeaf: Flag): Node<K, V>; /** * Return the found entry or undefined if not present in the root * @internal */ export declare function find<K, V>(root: Node<K, V>, shift: number, hash: number, key: K): Entry<K, V> | undefined; /** * Remove an entry from the root, returning the updated root. * Returns undefined if the node should be removed from the parent. * @internal */ export declare function without<K, V>(root: Node<K, V>, shift: number, hash: number, key: K): Node<K, V> | undefined; /** @internal */ export declare function forEach<K, V>(root: Node<K, V> | undefined, fn: (value: V, key: K) => void): void; /** @internal */ export declare function toArray<K, V>(root: Node<K, V> | undefined): [K, V][]; export {};