import { Token } from '@rimbu/base';
import type { RMap } from '@rimbu/collection-types/map';
import { EmptyBase, NonEmptyBase, type Row, type WithRow } from '@rimbu/collection-types/map-custom';
import { OptLazy, OptLazyOr, TraverseState, Update, type ArrayNonEmpty, type RelatedTo, type ToJSON } from '@rimbu/common';
import { Reducer, Stream, type StreamSource } from '@rimbu/stream';
import type { Table } from '@rimbu/table';
import type { TableBase } from '@rimbu/table/custom';
export interface ContextImplTypes extends TableBase.Types {
    readonly context: TableContext<this['_R'], this['_C'], string>;
}
export declare class TableEmpty<R, C, V, Tp extends ContextImplTypes> extends EmptyBase implements TableBase<R, C, V, Tp> {
    readonly context: WithRow<Tp, R, C, V>['context'];
    _NonEmptyType: WithRow<Tp, R, C, V>['nonEmpty'];
    constructor(context: WithRow<Tp, R, C, V>['context']);
    set(row: R, column: C, value: V): WithRow<Tp, R, C, V>['nonEmpty'];
    get rowMap(): WithRow<Tp, R, C, V>['rowMap'];
    get amountRows(): 0;
    streamRows(): Stream<R>;
    streamValues(): Stream<V>;
    addEntry(entry: readonly [R, C, V]): WithRow<Tp, R, C, V>['nonEmpty'];
    addEntries(entries: StreamSource<readonly [R, C, V]>): WithRow<Tp, R, C, V>['normal'] | any;
    remove(): WithRow<Tp, R, C, V>['normal'];
    removeRow(): WithRow<Tp, R, C, V>['normal'];
    removeRows(): WithRow<Tp, R, C, V>['normal'];
    removeAndGet(): undefined;
    removeRowAndGet(): undefined;
    removeEntries(): WithRow<Tp, R, C, V>['normal'];
    hasRowKey(): false;
    hasValueAt(): false;
    get<_, __, O>(row: R, column: C, otherwise?: OptLazy<O>): O;
    getRow(): WithRow<Tp, R, C, V>['row'];
    modifyAt(row: R, column: C, options: {
        ifNew?: OptLazyOr<V, Token>;
    }): WithRow<Tp, R, C, V>['normal'];
    updateAt(): WithRow<Tp, R, C, V>['normal'];
    filterRows(): WithRow<Tp, R, C, V>['normal'];
    mapValues(): WithRow<Tp, R, C, V>['normal'];
    toBuilder(): WithRow<Tp, R, C, V>['builder'];
    toString(): string;
    toJSON(): ToJSON<[R, [C, V][]][]>;
}
export declare class TableNonEmpty<R, C, V, Tp extends ContextImplTypes, TpR extends WithRow<Tp, R, C, V> = WithRow<Tp, R, C, V>> extends NonEmptyBase<[R, C, V]> implements TableBase.NonEmpty<R, C, V, Tp> {
    readonly context: TpR['context'];
    readonly rowMap: TpR['rowMapNonEmpty'];
    readonly size: number;
    _NonEmptyType: TpR['nonEmpty'];
    constructor(context: TpR['context'], rowMap: TpR['rowMapNonEmpty'], size: number);
    assumeNonEmpty(): any;
    asNormal(): any;
    copy(rowMap: TpR['rowMapNonEmpty'], size: number): TpR['nonEmpty'];
    copyE(rowMap: TpR['rowMap'], size: number): TpR['normal'];
    stream(): Stream.NonEmpty<[R, C, V]>;
    streamRows(): Stream.NonEmpty<R>;
    streamValues(): Stream.NonEmpty<V>;
    get amountRows(): number;
    hasRowKey<UR>(row: RelatedTo<R, UR>): boolean;
    hasValueAt<UR, UC>(row: RelatedTo<R, UR>, column: RelatedTo<C, UC>): boolean;
    get<UR, UC, O>(row: RelatedTo<R, UR>, column: RelatedTo<C, UC>, otherwise?: OptLazy<O>): V | O;
    getRow<UR>(row: RelatedTo<R, UR>): TpR['row'];
    set(row: R, column: C, value: V): TpR['nonEmpty'];
    addEntry(entry: readonly [R, C, V]): TpR['nonEmpty'];
    addEntries(entries: StreamSource<readonly [R, C, V]>): TpR['nonEmpty'];
    modifyAt(row: R, column: C, options: {
        ifNew?: OptLazyOr<V, Token>;
        ifExists?: ((value: V, remove: Token) => V | Token) | V;
    }): TpR['normal'];
    updateAt<UR, UC>(row: RelatedTo<R, UR>, column: RelatedTo<C, UC>, update: Update<V>): TpR['nonEmpty'];
    remove<UR, UC>(row: RelatedTo<R, UR>, column: RelatedTo<C, UC>): TpR['normal'];
    removeRow<UR>(row: RelatedTo<R, UR>): TpR['normal'];
    removeRows<UR>(rows: StreamSource<RelatedTo<R, UR>>): TpR['normal'];
    removeAndGet<UR, UC>(row: RelatedTo<R, UR>, column: RelatedTo<C, UC>): [TpR['normal'], V] | undefined;
    removeRowAndGet<UR>(row: RelatedTo<R, UR>): [TpR['normal'], TpR['rowNonEmpty']] | undefined;
    removeEntries<UR, UC>(entries: StreamSource<[RelatedTo<R, UR>, RelatedTo<C, UC>]>): TpR['normal'];
    forEach(f: (entry: [R, C, V], index: number, halt: () => void) => void, options?: {
        state?: TraverseState;
    }): void;
    filter(pred: (entry: [R, C, V], index: number, halt: () => void) => boolean, options?: {
        negate?: boolean;
    }): TpR['normal'];
    filterRows(pred: (entry: readonly [R, TpR['rowNonEmpty']], index: number, halt: () => void) => boolean, options?: {
        negate?: boolean;
    }): TpR['normal'];
    mapValues<V2>(mapFun: (value: V, row: R, column: C) => V2): (Tp & Row<R, C, V2>)['nonEmpty'];
    toArray(): ArrayNonEmpty<[R, C, V]>;
    toString(): string;
    toJSON(): ToJSON<[R, [C, V][]][]>;
    toBuilder(): TpR['builder'];
}
export declare class TableBuilder<R, C, V, Tp extends ContextImplTypes, TpR extends Tp & Row<R, C, V> = Tp & Row<R, C, V>> {
    readonly context: TpR['context'];
    source?: Table.NonEmpty<R, C, V> | undefined;
    _lock: number;
    _size: number;
    constructor(context: TpR['context'], source?: Table.NonEmpty<R, C, V> | undefined);
    _rowMap?: RMap.Builder<R, RMap.Builder<C, V>>;
    get rowMap(): RMap.Builder<R, RMap.Builder<C, V>>;
    checkLock(): void;
    get size(): number;
    get isEmpty(): boolean;
    get amountRows(): number;
    get: <UR, UC, O>(row: RelatedTo<R, UR>, column: RelatedTo<C, UC>, otherwise?: OptLazy<O>) => V | O;
    getRow: <UR>(row: RelatedTo<R, UR>) => any;
    hasValueAt: <UR, UC>(row: RelatedTo<R, UR>, column: RelatedTo<C, UC>) => boolean;
    hasRowKey: <UR>(row: RelatedTo<R, UR>) => boolean;
    set: (row: R, column: C, value: V) => boolean;
    addEntry: (entry: readonly [R, C, V]) => boolean;
    addEntries: (source: StreamSource<readonly [R, C, V]>) => boolean;
    remove: <UR, UC, O>(row: RelatedTo<R, UR>, column: RelatedTo<C, UC>, otherwise?: OptLazy<O>) => V | O;
    removeRow: <UR>(row: RelatedTo<R, UR>) => boolean;
    removeRows: <UR>(rows: StreamSource<RelatedTo<R, UR>>) => boolean;
    removeEntries: <UR = R, UC = C>(entries: StreamSource<[RelatedTo<R, UR>, RelatedTo<C, UC>]>) => boolean;
    modifyAt: (row: R, column: C, options: {
        ifNew?: OptLazyOr<V, Token>;
        ifExists?: ((currentValue: V, remove: Token) => V | Token) | V;
    }) => boolean;
    updateAt: <O>(row: R, column: C, update: Update<V>, otherwise?: OptLazy<O>) => V | O;
    forEach: (f: (entry: [R, C, V], index: number, halt: () => void) => void, options?: {
        state?: TraverseState;
    }) => void;
    build: () => TpR["normal"];
    buildMapValues: <V2>(mapFun: (value: V, row: R, column: C) => V2) => any;
}
export declare class TableContext<UR, UC, N extends string, Tp extends ContextImplTypes = ContextImplTypes> implements TableBase.Context<UR, UC, Tp> {
    readonly typeTag: N;
    readonly rowContext: WithRow<Tp, UR, UC, any>['rowContext'];
    readonly columnContext: WithRow<Tp, UR, UC, any>['columnContext'];
    constructor(typeTag: N, rowContext: WithRow<Tp, UR, UC, any>['rowContext'], columnContext: WithRow<Tp, UR, UC, any>['columnContext']);
    readonly _fixedKeys: readonly [UR, UC];
    get _types(): Tp;
    readonly _empty: Readonly<WithRow<Tp, UR, UC, any>["normal"]>;
    isNonEmptyInstance<R, C, V>(source: any): source is WithRow<Tp, R, C, V>['nonEmpty'];
    createNonEmpty<R extends UR, C extends UC, V>(rowMap: WithRow<Tp, R, C, V>['rowMapNonEmpty'], size: number): WithRow<Tp, R, C, V>['nonEmpty'];
    readonly empty: <R extends UR, C extends UC, V>() => WithRow<Tp, R, C, V>["normal"];
    readonly from: any;
    readonly of: any;
    readonly builder: <R extends UR, C extends UC, V>() => WithRow<Tp, R, C, V>["builder"];
    readonly reducer: <R extends UR, C extends UC, V>(source?: StreamSource<readonly [R, C, V]>) => Reducer<readonly [R, C, V], WithRow<Tp, R, C, V>["normal"]>;
    createBuilder<R extends UR, C extends UC, V>(source?: Table.NonEmpty<R, C, V>): WithRow<Tp, R, C, V>['builder'];
}
