@rimbu/sorted
Version:
Immutable SortedMap and SortedSet implementations for TypeScript
195 lines (194 loc) • 9.95 kB
text/typescript
import { Token } from '@rimbu/base';
import { type ArrayNonEmpty, IndexRange, OptLazy, OptLazyOr, Range, type RelatedTo, type ToJSON, TraverseState, Update } from '@rimbu/common';
import { Stream, type StreamSource } from '@rimbu/stream';
import type { SortedMap } from '@rimbu/sorted/map';
import type { SortedMapBuilder, SortedMapContext } from '@rimbu/sorted/map-custom';
import { SortedEmpty, SortedNonEmptyBase } from '@rimbu/sorted/common';
export declare class SortedMapEmpty<K = any, V = any> extends SortedEmpty implements SortedMap<K, V> {
readonly context: SortedMapContext<K>;
_NonEmptyType: SortedMap.NonEmpty<K, V>;
constructor(context: SortedMapContext<K>);
streamRange(): Stream<readonly [K, V]>;
streamKeys(): Stream<K>;
streamValues(): Stream<V>;
streamSliceIndex(): Stream<readonly [K, V]>;
minKey<O>(otherwise?: OptLazy<O>): O;
minValue<O>(otherwise?: OptLazy<O>): O;
maxKey<O>(otherwise?: OptLazy<O>): O;
maxValue<O>(otherwise?: OptLazy<O>): O;
get<_, O>(key: any, otherwise?: OptLazy<O>): O;
hasKey(): false;
findIndex(): number;
getKeyAtIndex<O>(index: number, otherwise?: OptLazy<O>): O;
getValueAtIndex<O>(index: number, otherwise?: OptLazy<O>): O;
set(key: K, value: V): SortedMap.NonEmpty<K, V>;
addEntry(entry: readonly [K, V]): SortedMap.NonEmpty<K, V>;
addEntries(entries: StreamSource<readonly [K, V]>): SortedMap.NonEmpty<K, V>;
removeKey(): SortedMap<K, V>;
removeKeys(): SortedMap<K, V>;
removeKeyAndGet(): undefined;
modifyAt(atKey: K, options: {
ifNew?: OptLazyOr<V, Token>;
}): SortedMap<K, V>;
mapValues<V2>(): SortedMap<K, V2>;
updateAt(): SortedMap<K, V>;
slice(): SortedMap<K, V>;
toBuilder(): SortedMapBuilder<K, V>;
toString(): string;
toJSON(): ToJSON<any[]>;
}
export declare abstract class SortedMapNode<K, V> extends SortedNonEmptyBase<readonly [K, V], SortedMapNode<K, V>> implements SortedMap.NonEmpty<K, V> {
_NonEmptyType: SortedMap.NonEmpty<K, V>;
abstract get context(): SortedMapContext<K>;
abstract get size(): number;
abstract stream(options?: {
reversed?: boolean;
}): Stream.NonEmpty<readonly [K, V]>;
abstract streamSliceIndex(range: IndexRange, options?: {
reversed?: boolean;
}): Stream<readonly [K, V]>;
abstract forEach(f: (entry: readonly [K, V], index: number, halt: () => void) => void, options?: {
state?: TraverseState;
}): void;
abstract get<U, O>(key: RelatedTo<K, U>, otherwise?: OptLazy<O>): V | O;
abstract findIndex(key: K): number;
abstract addInternal(entry: readonly [K, V], hash?: number): SortedMapNode<K, V>;
abstract modifyAtInternal(atKey: K, options: {
ifNew?: OptLazyOr<V, Token>;
ifExists?: ((currentEntry: V, remove: Token) => V | Token) | V;
}): SortedMapNode<K, V>;
abstract getInsertIndexOf(key: K): number;
abstract mapValues<V2>(mapFun: (value: V, key: K) => V2): SortedMapNode<K, V2>;
abstract toArray(): ArrayNonEmpty<readonly [K, V]>;
abstract normalize(): SortedMap<K, V>;
abstract min(): readonly [K, V];
abstract max(): readonly [K, V];
asNormal(): this;
getSliceRange(range: Range<K>): {
startIndex: number;
endIndex: number;
};
streamKeys(options?: {
reversed?: boolean;
}): Stream.NonEmpty<K>;
streamValues(options?: {
reversed?: boolean;
}): Stream.NonEmpty<V>;
streamRange(keyRange: Range<K>, options?: {
reversed?: boolean;
}): Stream<readonly [K, V]>;
minKey(): K;
minValue(): V;
maxKey(): K;
maxValue(): V;
hasKey<UK>(key: RelatedTo<K, UK>): boolean;
getKeyAtIndex<O>(index: number, otherwise?: OptLazy<O>): K | O;
getValueAtIndex<O>(index: number, otherwise?: OptLazy<O>): V | O;
addEntry(entry: readonly [K, V]): SortedMap.NonEmpty<K, V>;
addEntries(entries: StreamSource<readonly [K, V]>): SortedMap.NonEmpty<K, V>;
modifyAt(atKey: K, options: {
ifNew?: OptLazyOr<V, Token>;
ifExists?: ((currentEntry: V, remove: Token) => V | Token) | V;
}): SortedMap<K, V>;
set(key: K, value: V): SortedMap.NonEmpty<K, V>;
updateAt<U>(key: RelatedTo<K, U>, update: Update<V>): SortedMap.NonEmpty<K, V>;
removeKey<UK>(key: RelatedTo<K, UK>): SortedMap<K, V>;
removeKeys<UK>(keys: StreamSource<RelatedTo<K, UK>>): SortedMap<K, V>;
removeKeyAndGet<UK>(key: RelatedTo<K, UK>): [SortedMap<K, V>, V] | undefined;
filter(pred: (entry: readonly [K, V], index: number, halt: () => void) => boolean, options?: {
negate?: boolean;
}): SortedMap<K, V>;
take(amount: number): SortedMap<K, V> | any;
drop(amount: number): SortedMap<K, V>;
sliceIndex(range: IndexRange): SortedMap<K, V>;
slice(range: Range<K>): SortedMap<K, V>;
toBuilder(): SortedMapBuilder<K, V>;
toString(): string;
toJSON(): ToJSON<(readonly [K, V])[]>;
}
export declare class SortedMapLeaf<K, V> extends SortedMapNode<K, V> {
readonly context: SortedMapContext<K>;
entries: readonly (readonly [K, V])[];
constructor(context: SortedMapContext<K>, entries: readonly (readonly [K, V])[]);
copy(entries: readonly (readonly [K, V])[]): SortedMapLeaf<K, V>;
get size(): number;
stream(options?: {
reversed?: boolean;
}): Stream.NonEmpty<readonly [K, V]>;
streamSliceIndex(range: IndexRange, options?: {
reversed?: boolean;
}): Stream<readonly [K, V]>;
min(): readonly [K, V];
max(): readonly [K, V];
get<UK, O>(key: RelatedTo<K, UK>, otherwise?: OptLazy<O>): V | O;
findIndex(key: K): number;
getAtIndex<O>(index: number, otherwise?: OptLazy<O>): readonly [K, V] | O;
forEach(f: (entry: readonly [K, V], index: number, halt: () => void) => void, options?: {
state?: TraverseState;
}): void;
mapValues<V2>(mapFun: (value: V, key: K) => V2): SortedMapLeaf<K, V2>;
toArray(): ArrayNonEmpty<[K, V]>;
getInsertIndexOf(key: K): number;
addInternal(entry: readonly [K, V]): SortedMapNode<K, V>;
modifyAtInternal(key: K, options: {
ifNew?: OptLazyOr<V, Token>;
ifExists?: ((currentEntry: V, remove: Token) => V | Token) | V;
}): SortedMapNode<K, V>;
takeInternal(amount: number): SortedMapLeaf<K, V>;
dropInternal(amount: number): SortedMapLeaf<K, V>;
deleteMin(): [readonly [K, V], SortedMapLeaf<K, V>];
deleteMax(): [readonly [K, V], SortedMapLeaf<K, V>];
mutateSplitRight(index?: number): [readonly [K, V], SortedMapLeaf<K, V>];
mutateGiveToLeft(left: SortedMapLeaf<K, V>, toLeft: readonly [K, V]): [readonly [K, V], SortedMapLeaf<K, V>];
mutateGiveToRight(right: SortedMapLeaf<K, V>, toRight: readonly [K, V]): [readonly [K, V], SortedMapLeaf<K, V>];
mutateGetFromLeft(left: SortedMapLeaf<K, V>, toMe: readonly [K, V]): [readonly [K, V], SortedMapLeaf<K, V>];
mutateGetFromRight(right: SortedMapLeaf<K, V>, toMe: readonly [K, V]): [readonly [K, V], SortedMapLeaf<K, V>];
mutateJoinLeft(left: SortedMapLeaf<K, V>, entry: readonly [K, V]): void;
mutateJoinRight(right: SortedMapLeaf<K, V>, entry: readonly [K, V]): void;
normalize(): SortedMap<K, V>;
}
export declare class SortedMapInner<K, V> extends SortedMapNode<K, V> {
readonly context: SortedMapContext<K>;
entries: readonly (readonly [K, V])[];
children: readonly SortedMapNode<K, V>[];
readonly size: number;
constructor(context: SortedMapContext<K>, entries: readonly (readonly [K, V])[], children: readonly SortedMapNode<K, V>[], size: number);
get mutateChildren(): SortedMapNode<K, V>[];
copy(entries?: readonly (readonly [K, V])[], children?: readonly SortedMapNode<K, V>[], size?: number): SortedMapInner<K, V>;
stream(options?: {
reversed?: boolean;
}): Stream.NonEmpty<readonly [K, V]>;
streamSliceIndex(range: IndexRange, options?: {
reversed?: boolean;
}): Stream<readonly [K, V]>;
min(): readonly [K, V];
max(): readonly [K, V];
get<UK, O>(key: RelatedTo<K, UK>, otherwise?: OptLazy<O>): V | O;
findIndex(key: K): number;
getAtIndex<O>(index: number, otherwise?: OptLazy<O>): readonly [K, V] | O;
forEach(f: (entry: readonly [K, V], index: number, halt: () => void) => void, options?: {
state?: TraverseState;
}): void;
mapValues<V2>(mapFun: (value: V, key: K) => V2): SortedMapInner<K, V2>;
toArray(): ArrayNonEmpty<readonly [K, V]>;
getInsertIndexOf(key: K): number;
addInternal(entry: readonly [K, V]): SortedMapInner<K, V>;
modifyAtInternal(key: K, options: {
ifNew?: OptLazyOr<V, Token>;
ifExists?: ((currentEntry: V, remove: Token) => V | Token) | V;
}): SortedMapInner<K, V>;
takeInternal(amount: number): SortedMapNode<K, V>;
dropInternal(amount: number): SortedMapNode<K, V>;
deleteMin(): [readonly [K, V], SortedMapInner<K, V>];
deleteMax(): [readonly [K, V], SortedMapInner<K, V>];
mutateSplitRight(index?: number): [readonly [K, V], SortedMapInner<K, V>];
mutateGiveToLeft(left: SortedMapInner<K, V>, toLeft: readonly [K, V]): [readonly [K, V], SortedMapInner<K, V>];
mutateGiveToRight(right: SortedMapInner<K, V>, toRight: readonly [K, V]): [readonly [K, V], SortedMapInner<K, V>];
mutateGetFromLeft(left: SortedMapInner<K, V>, toMe: readonly [K, V]): [readonly [K, V], SortedMapInner<K, V>];
mutateGetFromRight(right: SortedMapInner<K, V>, toMe: readonly [K, V]): [readonly [K, V], SortedMapInner<K, V>];
mutateJoinLeft(left: SortedMapInner<K, V>, entry: readonly [K, V]): void;
mutateJoinRight(right: SortedMapInner<K, V>, entry: readonly [K, V]): void;
normalizeDownsizeChild(childIndex: number, newChild: SortedMapNode<K, V>, newSize: number): SortedMapInner<K, V>;
normalizeIncreaseChild(childIndex: number, newChild: SortedMapNode<K, V>, newSize: number): SortedMapInner<K, V>;
normalize(): SortedMap<K, V>;
}