UNPKG

@rimbu/proximity

Version:

Immutable ProximityMap implementation for TypeScript

47 lines (46 loc) 2.3 kB
import type { Token } from '@rimbu/base'; import type { RMapBase } from '@rimbu/collection-types/map-custom'; import type { OptLazy, OptLazyOr, RelatedTo, TraverseState } from '@rimbu/common'; import type { StreamSource } from '@rimbu/stream'; import type { ProximityMap } from '@rimbu/proximity/map'; /** * Mutable builder used to efficiently construct new immutable {@link ProximityMap} instances.<br/> * <br/> * The builder stores entries in an internal `HashMap.Builder` and only wraps the result * into a `ProximityMap` when {@link ProximityMapBuilder.build | build} (or * {@link ProximityMapBuilder.buildMapValues | buildMapValues}) is called. * * @typeparam K - the key type * @typeparam V - the value type */ export declare class ProximityMapBuilder<K, V> implements ProximityMap.Builder<K, V> { readonly context: ProximityMap.Context<K>; private source?; private readonly internalBuilder; constructor(context: ProximityMap.Context<K>, source?: ProximityMap.NonEmpty<K, V> | undefined); get size(): number; get isEmpty(): boolean; /** * Applying `get()` to the Builder does NOT apply the proximity algorithm - which would * be pointless at this construction stage; the internal, hash-based builder * is queried instead * */ get: <UK, O>(key: RelatedTo<K, UK>, otherwise?: OptLazy<O>) => V | O; hasKey: <UK = K>(key: RelatedTo<K, UK>) => boolean; forEach: (f: (entry: readonly [K, V], index: number, halt: () => void) => void, options?: { state?: TraverseState; }) => void; addEntry: (entry: readonly [K, V]) => boolean; addEntries: (entries: StreamSource<readonly [K, V]>) => boolean; set: (key: K, value: V) => boolean; removeKey: <UK, O>(key: RelatedTo<K, UK>, otherwise?: OptLazy<O>) => V | O; removeKeys: <UK = K>(keys: StreamSource<RelatedTo<K, UK>>) => boolean; modifyAt: (key: K, options: { ifNew?: OptLazyOr<V, typeof Token>; ifExists?: (<V2 extends V = V>(currentValue: V & V2, remove: typeof Token) => V | typeof Token) | V; }) => boolean; updateAt: <O>(key: K, update: RMapBase.Update<V>, otherwise?: OptLazy<O>) => V | O; build: () => ProximityMap<K, V>; buildMapValues: <V2>(mapFun: (value: V, key: K) => V2) => ProximityMap<K, V2>; }