UNPKG

@rimbu/proximity

Version:

Immutable ProximityMap implementation for TypeScript

57 lines (56 loc) 2.88 kB
import type { Token } from '@rimbu/base'; import type { RMapBase } from '@rimbu/collection-types/map-custom'; import { OptLazy, type ArrayNonEmpty, type OptLazyOr, type RelatedTo, type ToJSON, type TraverseState } from '@rimbu/common'; import type { HashMap } from '@rimbu/hashed/map'; import type { FastIterator, Stream, StreamSource } from '@rimbu/stream'; import type { ProximityMap } from '@rimbu/proximity/map'; /** * Concrete non-empty implementation of {@link ProximityMap.NonEmpty}.<br/> * <br/> * It stores entries in a non-empty `HashMap` and applies the configured distance function * when resolving lookups via {@link ProximityMapNonEmpty.get}. * * @typeparam K - the key type * @typeparam V - the value type */ export declare class ProximityMapNonEmpty<K, V> implements ProximityMap.NonEmpty<K, V> { readonly context: ProximityMap.Context<K>; private readonly internalMap; _NonEmptyType: ProximityMap.NonEmpty<K, V>; readonly isEmpty = false; constructor(context: ProximityMap.Context<K>, internalMap: HashMap.NonEmpty<K, V>); private plugInternalMap; get size(): number; stream(): Stream.NonEmpty<readonly [K, V]>; addEntries(entries: StreamSource<readonly [K, V]>): ProximityMap.NonEmpty<K, V>; updateAt<UK = K>(key: RelatedTo<K, UK>, update: RMapBase.Update<V>): ProximityMap.NonEmpty<K, V>; nonEmpty(): this is ProximityMap.NonEmpty<K, V>; assumeNonEmpty(): this; asNormal(): ProximityMap<K, V>; streamKeys(): Stream.NonEmpty<K>; streamValues(): Stream.NonEmpty<V>; mapValues<V2>(mapFun: (value: V, key: K) => V2): ProximityMap.NonEmpty<K, V2>; toArray(): ArrayNonEmpty<readonly [K, V]>; get<UK = K>(key: RelatedTo<K, UK>): V | undefined; get<UK, O>(key: RelatedTo<K, UK>, otherwise: OptLazy<O>): V | O; hasKey<UK = K>(key: RelatedTo<K, UK>): boolean; removeKey<UK = K>(key: RelatedTo<K, UK>): ProximityMap<K, V>; removeKeys<UK = K>(keys: StreamSource<RelatedTo<K, UK>>): ProximityMap<K, V>; removeKeyAndGet<UK = K>(key: RelatedTo<K, UK>): [ProximityMap<K, V>, V] | undefined; forEach(f: (entry: readonly [K, V], index: number, halt: () => void) => void, options?: { state?: TraverseState; }): void; filter(pred: (entry: readonly [K, V], index: number, halt: () => void) => boolean, options?: { negate?: boolean; }): ProximityMap<K, V>; toString(): string; toJSON(): ToJSON<(readonly [K, V])[], string>; [Symbol.iterator](): FastIterator<readonly [K, V]>; set(key: K, value: V): ProximityMap.NonEmpty<K, V>; addEntry(entry: readonly [K, V]): ProximityMap.NonEmpty<K, V>; modifyAt(atKey: K, options: { ifNew?: OptLazyOr<V, Token>; ifExists?: <V2 extends V = V>(currentEntry: V & V2, remove: Token) => V | Token; }): ProximityMap<K, V>; toBuilder(): ProximityMap.Builder<K, V>; }