/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { CursorLocationType, FieldKey, FieldUpPath, PathRootPrefix, TreeNodeSchemaIdentifier, TreeValue, UpPath, Value } from "../../core/index.js";
import { ReferenceCountedBase } from "../../util/index.js";
import { SynchronousCursor } from "../treeCursorUtils.js";
import { ChunkedCursor, TreeChunk, cursorChunk } from "./chunk.js";
/**
 * Create a tree chunk with ref count 1.
 *
 * @param shape - describes the semantics and layout of `values`.
 * @param values - provides exclusive ownership of this array to this object (which might mutate it in the future).
 */
export declare function uniformChunk(shape: ChunkShape, values: TreeValue[]): TreeChunk;
/**
 * Chunk which handles a sequence of trees with identical "shape" (see `TreeShape`).
 *
 * Separates shape from content,
 * allowing deduplication of shape information and storing of content as a flat sequence of values.
 */
export declare class UniformChunk extends ReferenceCountedBase implements TreeChunk {
    shape: ChunkShape;
    values: TreeValue[];
    /**
     * Create a tree chunk with ref count 1.
     *
     * @param shape - describes the semantics and layout of `values`.
     * @param values - provides exclusive ownership of this array to this object (which might mutate it in the future).
     */
    constructor(shape: ChunkShape, values: TreeValue[]);
    get topLevelLength(): number;
    clone(): UniformChunk;
    cursor(): Cursor;
    protected dispose(): void;
}
/**
 * The "shape" of a field.
 *
 * Requires that all trees in the field have the same shape, which is described by `TreeShape`.
 * Note that this requirement means that not all fields can be described using this type.
 */
export type FieldShape = readonly [FieldKey, TreeShape, number];
/**
 * The "shape" of a tree.
 * Does not contain the actual values from  the tree, but describes everything else,
 * including where the values would be found in a flat values array.
 *
 * Note that since this requires fields to have uniform shapes (see `FieldShape`),
 * not all trees can have their shape described using this type.
 */
export declare class TreeShape {
    readonly type: TreeNodeSchemaIdentifier;
    readonly hasValue: boolean;
    readonly fieldsArray: readonly FieldShape[];
    readonly fields: ReadonlyMap<FieldKey, OffsetShape>;
    readonly fieldsOffsetArray: readonly OffsetShape[];
    readonly valuesPerTopLevelNode: number;
    readonly positions: readonly NodePositionInfo[];
    constructor(type: TreeNodeSchemaIdentifier, hasValue: boolean, fieldsArray: readonly FieldShape[]);
    equals(other: TreeShape): boolean;
    withTopLevelLength(topLevelLength: number): ChunkShape;
}
/**
 * The shape (see `TreeShape`) of a sequence of trees, all with the same shape (like `FieldShape`, but without a field key).
 *
 * This shape is optimized (by caching derived data like the positions array),
 * so that when paired with a value array it can be efficiently traversed like a tree by an {@link ITreeCursorSynchronous}.
 * See {@link uniformChunk} for how to do this.
 *
 * TODO: consider storing shape information in WASM
 */
export declare class ChunkShape {
    readonly treeShape: TreeShape;
    readonly topLevelLength: number;
    readonly positions: readonly (NodePositionInfo | undefined)[];
    constructor(treeShape: TreeShape, topLevelLength: number);
    equals(other: ChunkShape): boolean;
}
/**
 * Shape of a field (like `FieldShape`) but with information about how it would be offset within a chunk because of its parents.
 */
declare class OffsetShape {
    readonly shape: TreeShape;
    readonly topLevelLength: number;
    readonly offset: number;
    readonly key: FieldKey;
    readonly indexOfParentField: number | undefined;
    /**
     * @param shape - the shape of each child in this field
     * @param topLevelLength - number of top level nodes in this sequence chunk (either field within a chunk, or top level chunk)
     * @param offset - number of nodes before this in the parent's subtree
     * @param key - field key
     * @param indexOfParentField - index of node with this shape
     */
    constructor(shape: TreeShape, topLevelLength: number, offset: number, key: FieldKey, indexOfParentField: number | undefined);
}
/**
 * Information about a node at a specific position within a uniform chunk.
 */
declare class NodePositionInfo implements UpPath {
    readonly parent: NodePositionInfo | undefined;
    readonly parentField: FieldKey;
    readonly parentIndex: number;
    readonly indexOfParentField: number | undefined;
    readonly indexOfParentPosition: number | undefined;
    readonly shape: TreeShape;
    readonly topLevelLength: number;
    readonly valueOffset: number;
    /**
     * @param parent - TODO
     * @param parentField - TODO
     * @param parentIndex - indexWithinParentField
     * @param indexOfParentField - which field of the parent `parentIndex` is indexing into to locate this.
     * @param indexOfParentPosition - Index of parent NodePositionInfo in positions array. TODO: use offsets to avoid copying at top level?
     * @param shape - Shape of the top level sequence this node is part of
     * @param valueOffset - TODO
     */
    constructor(parent: NodePositionInfo | undefined, // TODO; general UpPath to allow prefixing here?
    parentField: FieldKey, parentIndex: number, indexOfParentField: number | undefined, indexOfParentPosition: number | undefined, shape: TreeShape, // Shape of sequence that contains this node (top level is parent of this node)
    topLevelLength: number, valueOffset: number);
}
/**
 * The cursor implementation for `UniformChunk`.
 *
 * Works by tracking its location in the chunk's `positions` array.
 */
declare class Cursor extends SynchronousCursor implements ChunkedCursor {
    private readonly chunk;
    private positionIndex;
    private nodePositionInfo;
    private readonly shape;
    private readonly positions;
    mode: CursorLocationType;
    private fieldKey?;
    private indexOfField;
    constructor(chunk: UniformChunk);
    get [cursorChunk](): UniformChunk | undefined;
    atChunkRoot(): boolean;
    fork(): Cursor;
    /**
     * Change the current node within the chunk.
     * See `nodeInfo` for getting data about the current node.
     *
     * @param positionIndex - index of the position of the newly selected node in `positions`.
     * This is NOT an index within a field, and is not bounds checked.
     */
    private moveToPosition;
    /**
     * Gets information about the current node.
     *
     * When in Nodes mode, this means the node this cursor is current at.
     * When if fields mode, this means the node which is the parent of the current field.
     * This cursor is in Nodes mode at the root, so there is no case where a fields mode does not have a parent.
     *
     * @param requiredMode - asserts that the mode matches this. Since the semantics of this function are somewhat mode dependent,
     * providing this ensures that the caller knows what the results will mean.
     */
    private nodeInfo;
    nextField(): boolean;
    exitField(): void;
    getFieldKey(): FieldKey;
    getFieldLength(): number;
    firstNode(): boolean;
    enterNode(childIndex: number): void;
    /**
     * Enter the current field, at `childIndex`.
     * @param childIndex - index into current field to navigate to. Must be non-negative integer.
     */
    private enterNodeInner;
    private enterRootNodeInner;
    getFieldPath(prefix?: PathRootPrefix): FieldUpPath;
    getPath(prefix?: PathRootPrefix): UpPath | undefined;
    get fieldIndex(): number;
    readonly chunkStart: number;
    get chunkLength(): number;
    seekNodes(offset: number): boolean;
    nextNode(): boolean;
    exitNode(): void;
    firstField(): boolean;
    enterField(key: FieldKey): void;
    get type(): TreeNodeSchemaIdentifier;
    get value(): Value;
}
export {};
//# sourceMappingURL=uniformChunk.d.ts.map