import { OverlayPoint } from './OverlayPoint';
import { type ITimestampStruct } from '../../../json-crdt-patch/clock';
import { Slice } from '../slice/Slice';
import { UndEndIterator, type UndEndNext } from '../../../util/iterator';
import type { Point } from '../rga/Point';
import type { Range } from '../rga/Range';
import type { Chunk } from '../../../json-crdt/nodes/rga';
import type { Peritext } from '../Peritext';
import type { Stateful } from '../types';
import type { Printable } from 'tree-dump/lib/types';
import type { OverlayPair, OverlayTuple } from './types';
import type { Comparator, HeadlessNode } from 'sonic-forest/lib/types';
import type { SliceType } from '../slice';
export declare const insert: <T, N extends HeadlessNode & T>(root: N | undefined, node: N, comparator: Comparator<T>) => N | undefined;
/**
 * Overlay is a tree structure that represents all the intersections of slices
 * in the text. It is used to quickly find all the slices that overlap a
 * given point in the text. The overlay is a read-only structure, its state
 * is changed only by calling the `refresh` method, which updates the overlay
 * based on the current state of the text and slices.
 */
export declare class Overlay<T = string> implements Printable, Stateful {
    protected readonly txt: Peritext<T>;
    /**
     * @todo Make it an AVL tree.
     */
    root: OverlayPoint<T> | undefined;
    root2: OverlayPoint<T> | undefined;
    /** A virtual absolute start point, used when the absolute start is missing. */
    readonly START: OverlayPoint<T>;
    /** A virtual absolute end point, used when the absolute end is missing. */
    readonly END: OverlayPoint<T>;
    constructor(txt: Peritext<T>);
    private point;
    first(): OverlayPoint<T> | undefined;
    last(): OverlayPoint<T> | undefined;
    firstMarker(): OverlayPoint<T> | undefined;
    lastMarker(): OverlayPoint<T> | undefined;
    get(point: Point<T>): OverlayPoint<T> | undefined;
    getMarker(point: Point<T>): OverlayPoint<T> | undefined;
    /**
     * Retrieve overlay point or the previous one, measured in spacial dimension.
     */
    getOrNextLower(point: Point<T>): OverlayPoint<T> | undefined;
    /**
     * Retrieve overlay point or the next one, measured in spacial dimension.
     */
    getOrNextHigher(point: Point<T>): OverlayPoint<T> | undefined;
    /**
     * Retrieve a {@link OverlayPoint} at the specified point or the
     * previous one, measured in spacial dimension.
     */
    getOrNextLowerMarker(point: Point<T>): OverlayPoint<T> | undefined;
    /** @todo Rename to `chunks()`. */
    chunkSlices0(chunk: Chunk<T> | undefined, p1: Point<T>, p2: Point<T>, callback: (chunk: Chunk<T>, off: number, len: number) => boolean | void): Chunk<T> | undefined;
    points0(after: undefined | OverlayPoint<T>, inclusive?: boolean): UndEndNext<OverlayPoint<T>>;
    points(after?: undefined | OverlayPoint<T>, inclusive?: boolean): IterableIterator<OverlayPoint<T>>;
    /**
     * Returns all {@link OverlayPoint} instances in the overlay, starting
     * from the given marker point, not including the marker point itself.
     *
     * If the `after` parameter is not provided, the iteration starts from the
     * first marker point in the overlay.
     *
     * @param after The marker point after which to start the iteration.
     * @returns All marker points in the overlay, starting from the given marker
     *     point.
     */
    markers0(after: undefined | OverlayPoint<T>): UndEndNext<OverlayPoint<T>>;
    markers(after?: undefined | OverlayPoint<T>): UndEndIterator<OverlayPoint<T>>;
    /**
     * Returns all {@link OverlayPoint} instances in the overlay, starting
     * from a give {@link Point}, including any marker overlay points that are
     * at the same position as the given point.
     *
     * @param point Point (inclusive) from which to return all markers.
     * @returns All marker points in the overlay, starting from the given marker
     *     point.
     */
    markersFrom0(point: Point<T>): UndEndNext<OverlayPoint<T>>;
    /**
     * Returns a pair of overlay marker points for each pair of adjacent marker
     * points in the overlay, starting from a given point (which may not be a
     * marker). The very first point in the first pair might be `undefined`, if
     * the given point is not a marker. Similarly, the very last point in the last
     * pair might be `undefined`, if the iteration end point is not a marker.
     *
     * @param start Start point of the iteration, inclusive.
     * @param end End point of the iteration. If not provided, the iteration
     *     continues until the end of the overlay.
     * @returns Iterator that returns pairs of overlay points.
     */
    markerPairs0(start: Point<T>, end?: Point<T>): UndEndNext<OverlayPair<T>>;
    pairs0(after: undefined | OverlayPoint<T>, inclusive?: boolean): UndEndNext<OverlayPair<T>>;
    pairs(after?: undefined | OverlayPoint<T>, inclusive?: boolean): IterableIterator<OverlayPair<T>>;
    tuples0(after: undefined | OverlayPoint<T>, inclusive?: boolean): UndEndNext<OverlayTuple<T>>;
    tuples(after?: undefined | OverlayPoint<T>, inclusive?: boolean): IterableIterator<OverlayTuple<T>>;
    /**
     * Finds the first point that satisfies the given predicate function.
     *
     * @param predicate Predicate function to find the point, returns true if the
     *     point is found.
     * @returns The first point that satisfies the predicate, or undefined if no
     *     point is found.
     */
    find(predicate: (point: OverlayPoint<T>) => boolean): OverlayPoint<T> | undefined;
    /**
     * Finds all slices that are contained within the given range. A slice is
     * considered contained if its start and end points are within the range,
     * inclusive (uses {@link Range#contains} method to check containment).
     *
     * @param range The range to search for contained slices.
     * @returns A set of slices that are contained within the given range.
     */
    findContained(range: Range<T>): Set<Slice<T>>;
    /**
     * Finds all slices that overlap with the given range. A slice is considered
     * overlapping if its start or end point is within the range, inclusive
     * (uses {@link Range#containsPoint} method to check overlap).
     *
     * @param range The range to search for overlapping slices.
     * @returns A set of slices that overlap with the given range.
     */
    findOverlapping(range: Range<T>): Set<Slice<T>>;
    /**
     * Returns a summary of how different slice types overlap with the given range.
     *
     * @param range Range over which to search for slices.
     * @param endOnMarker If set to a positive number, the search will stop after
     *     the given number of marker points have been observed.
     * @returns Summary of the slices in this range. `complete` contains all
     *     "Overwrite" slice types, which overlay the full range, which have not
     *     been removed by "Erase" slice type. `partial` contains all "Overwrite"
     *     slice types, which mark a part of the range, and have not been removed
     *     by "Erase" slice type.
     */
    stat(range: Range<T>, endOnMarker?: number): [complete: Set<SliceType>, partial: Set<SliceType>, markerCount: number];
    /**
     * Returns `true` if the current character is a marker sentinel.
     *
     * @param id ID of the point to check.
     * @returns Whether the point is a marker point.
     */
    isMarker(id: ITimestampStruct): boolean;
    skipMarkers(point: Point<T>, direction: -1 | 1): boolean;
    /** ------------------------------------------------------ {@link Stateful} */
    hash: number;
    private clear;
    refresh(slicesOnly?: boolean): number;
    readonly slices: Map<Slice<T>, [start: OverlayPoint<T>, end: OverlayPoint<T>]>;
    private upsertSlice;
    private delSlice;
    /**
     * Inserts a point into the tree, sorted by spatial dimension.
     * Retrieve an existing {@link OverlayPoint} or create a new one, inserted
     * in the tree, sorted by spatial dimension.
     *
     * @param point Point to insert.
     * @returns Returns the existing point if it was already in the tree.
     */
    private upsertPoint;
    private delPoint;
    leadingTextHash: number;
    protected refreshTextSlices(stateTotal: number): number;
    /** ----------------------------------------------------- {@link Printable} */
    toString(tab?: string): string;
}
