UNPKG

@rimbu/multimap

Version:

An immutable Map where each key can have multiple values

118 lines (117 loc) 6.76 kB
import type { RMap, RSet } from '@rimbu/collection-types'; import { EmptyBase, NonEmptyBase, type KeyValue, type WithKeyValue } from '@rimbu/collection-types/map-custom'; import { OptLazy, TraverseState, type ArrayNonEmpty, type RelatedTo, type ToJSON } from '@rimbu/common'; import { Reducer, Stream, type StreamSource } from '@rimbu/stream'; import type { MultiMap } from '@rimbu/multimap'; import type { MultiMapBase } from '@rimbu/multimap/custom'; export interface ContextImplTypes extends MultiMapBase.Types { readonly context: MultiMapContext<this['_K'], this['_V'], string>; } export declare class MultiMapEmpty<K, V, Tp extends ContextImplTypes> extends EmptyBase implements MultiMapBase<K, V, Tp> { readonly context: WithKeyValue<Tp, K, V>['context']; _NonEmptyType: WithKeyValue<Tp, K, V>['nonEmpty']; constructor(context: WithKeyValue<Tp, K, V>['context']); get keyMap(): WithKeyValue<Tp, K, V>['keyMap']; get keySize(): 0; streamKeys(): Stream<K>; streamValues(): Stream<V>; hasKey(): false; hasEntry(): false; add(key: K, value: V): WithKeyValue<Tp, K, V>['nonEmpty']; addEntries(entries: StreamSource<readonly [K, V]>): any; getValues(): WithKeyValue<Tp, K, V>['keyMapValues']; setValues(key: K, values: StreamSource<V>): WithKeyValue<Tp, K, V>['nonEmpty']; modifyAt(atKey: K, options: { ifNew?: OptLazy<StreamSource<V>>; }): WithKeyValue<Tp, K, V>['normal']; removeKey(): WithKeyValue<Tp, K, V>['normal']; removeKeys(): WithKeyValue<Tp, K, V>['normal']; removeKeyAndGet(): undefined; removeEntry(): WithKeyValue<Tp, K, V>['normal']; removeEntries(): WithKeyValue<Tp, K, V>['normal']; toBuilder(): WithKeyValue<Tp, K, V>['builder']; toString(): string; toJSON(): ToJSON<[K, V[]][]>; } export declare class MultiMapNonEmpty<K, V, Tp extends ContextImplTypes, TpG extends WithKeyValue<Tp, K, V> = WithKeyValue<Tp, K, V>> extends NonEmptyBase<[K, V]> implements MultiMapBase.NonEmpty<K, V, Tp> { readonly context: TpG['context']; readonly keyMap: TpG['keyMapNonEmpty']; readonly size: number; _NonEmptyType: TpG['nonEmpty']; constructor(context: TpG['context'], keyMap: TpG['keyMapNonEmpty'], size: number); assumeNonEmpty(): any; asNormal(): any; copy(keyMap: TpG['keyMapNonEmpty'], size: number): TpG['nonEmpty']; copyE(keyMap: TpG['keyMap'], size: number): TpG['normal']; stream(): Stream.NonEmpty<[K, V]>; streamKeys(): Stream.NonEmpty<K>; streamValues(): Stream.NonEmpty<V>; get keySize(): number; hasKey<U>(key: RelatedTo<K, U>): boolean; hasEntry<U>(key: RelatedTo<K, U>, value: V): boolean; getValues<U>(key: RelatedTo<K, U>): TpG['keyMapValues']; add(key: K, value: V): TpG['nonEmpty']; addEntries(entries: StreamSource<readonly [K, V]>): TpG['nonEmpty']; setValues(key: K, values: any): any; removeKey<UK>(key: RelatedTo<K, UK>): TpG['normal']; removeKeys<UK>(keys: StreamSource<RelatedTo<K, UK>>): TpG['normal']; removeKeyAndGet<UK>(key: RelatedTo<K, UK>): [TpG['normal'], TpG['keyMapValuesNonEmpty']] | undefined; removeEntry<UK, UV>(key: RelatedTo<K, UK>, value: RelatedTo<V, UV>): TpG['normal']; removeEntries<UK, UV>(entries: StreamSource<[RelatedTo<K, UK>, RelatedTo<V, UV>]>): TpG['normal']; filter(pred: (entry: [K, V], index: number, halt: () => void) => boolean, options?: { negate?: boolean; }): TpG['normal']; forEach(f: (entry: [K, V], index: number, halt: () => void) => void, options?: { state?: TraverseState; }): void; modifyAt(atKey: K, options: { ifNew?: OptLazy<StreamSource<V>>; ifExists?: ((currentValues: TpG['keyMapValuesNonEmpty']) => StreamSource<V>) | StreamSource<V>; }): TpG['normal']; toArray(): ArrayNonEmpty<[K, V]>; toString(): string; toJSON(): ToJSON<[K, V[]][]>; toBuilder(): TpG['builder']; } export declare class MultiMapBuilder<K, V, Tp extends ContextImplTypes, TpG extends WithKeyValue<Tp, K, V> = WithKeyValue<Tp, K, V>> implements MultiMapBase.Builder<K, V, Tp> { readonly context: TpG['context']; source?: MultiMap.NonEmpty<K, V> | undefined; _lock: number; _size: number; constructor(context: TpG['context'], source?: MultiMap.NonEmpty<K, V> | undefined); _keyMap?: RMap.Builder<K, RSet.Builder<V>>; get keyMap(): RMap.Builder<K, RSet.Builder<V>>; checkLock(): void; get size(): number; get isEmpty(): boolean; getValues: <UK>(key: RelatedTo<K, UK>) => any; hasKey: <UK>(key: RelatedTo<K, UK>) => boolean; hasEntry: <UK>(key: RelatedTo<K, UK>, value: V) => boolean; add: (key: K, value: V) => boolean; addEntries: (source: StreamSource<readonly [K, V]>) => boolean; setValues: (key: K, source: StreamSource<V>) => boolean; removeEntry: <UK, UV>(key: RelatedTo<K, UK>, value: RelatedTo<V, UV>) => boolean; removeEntries: <UK, UV>(entries: StreamSource<[RelatedTo<K, UK>, RelatedTo<V, UV>]>) => boolean; removeKey: <UK>(key: RelatedTo<K, UK>) => boolean; removeKeys: <UK>(keys: StreamSource<RelatedTo<K, UK>>) => boolean; forEach: (f: (entry: [K, V], index: number, halt: () => void) => void, options?: { reversed?: boolean; state?: TraverseState; }) => void; build: () => TpG["normal"]; } export declare class MultiMapContext<UK, UV, N extends string, Tp extends ContextImplTypes = ContextImplTypes> implements MultiMapBase.Context<UK, UV, Tp> { readonly typeTag: N; readonly keyMapContext: (Tp & KeyValue<UK, UV>)['keyMapContext']; readonly keyMapValuesContext: (Tp & KeyValue<UK, UV>)['keyMapValuesContext']; constructor(typeTag: N, keyMapContext: (Tp & KeyValue<UK, UV>)['keyMapContext'], keyMapValuesContext: (Tp & KeyValue<UK, UV>)['keyMapValuesContext']); readonly _empty: Readonly<WithKeyValue<Tp, UK, UV>["normal"]>; isNonEmptyInstance<K, V>(source: any): source is WithKeyValue<Tp, K, V>['nonEmpty']; createNonEmpty<K extends UK, V extends UV>(keyMap: WithKeyValue<Tp, K, V>['keyMapNonEmpty'], size: number): WithKeyValue<Tp, K, V>['nonEmpty']; readonly empty: <K extends UK, V extends UV>() => WithKeyValue<Tp, K, V>["normal"]; readonly from: any; readonly of: <K extends UK, V extends UV>(entries_0: readonly [K, V], ...entries: (readonly [K, V])[]) => [K, V] extends [UK, UV] ? WithKeyValue<Tp, K, V>["nonEmpty"] : never; readonly builder: <K extends UK, V extends UV>() => WithKeyValue<Tp, K, V>["builder"]; readonly reducer: <K extends UK, V extends UV>(source?: StreamSource<readonly [K, V]>) => Reducer<readonly [K, V], WithKeyValue<Tp, K, V>["normal"]>; createBuilder<K, V>(source?: MultiMap.NonEmpty<K, V>): WithKeyValue<Tp, K, V>['builder']; }