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: (root: N | undefined, node: N, comparator: Comparator) => 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 implements Printable, Stateful { protected readonly txt: Peritext; /** * @todo Make it an AVL tree. */ root: OverlayPoint | undefined; root2: OverlayPoint | undefined; /** A virtual absolute start point, used when the absolute start is missing. */ readonly START: OverlayPoint; /** A virtual absolute end point, used when the absolute end is missing. */ readonly END: OverlayPoint; constructor(txt: Peritext); private point; first(): OverlayPoint | undefined; last(): OverlayPoint | undefined; firstMarker(): OverlayPoint | undefined; lastMarker(): OverlayPoint | undefined; get(point: Point): OverlayPoint | undefined; getMarker(point: Point): OverlayPoint | undefined; /** * Retrieve overlay point or the previous one, measured in spacial dimension. */ getOrNextLower(point: Point): OverlayPoint | undefined; /** * Retrieve overlay point or the next one, measured in spacial dimension. */ getOrNextHigher(point: Point): OverlayPoint | undefined; /** * Retrieve a {@link OverlayPoint} at the specified point or the * previous one, measured in spacial dimension. */ getOrNextLowerMarker(point: Point): OverlayPoint | undefined; /** @todo Rename to `chunks()`. */ chunkSlices0(chunk: Chunk | undefined, p1: Point, p2: Point, callback: (chunk: Chunk, off: number, len: number) => boolean | void): Chunk | undefined; points0(after: undefined | OverlayPoint, inclusive?: boolean): UndEndNext>; points(after?: undefined | OverlayPoint, inclusive?: boolean): IterableIterator>; /** * 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): UndEndNext>; markers(after?: undefined | OverlayPoint): UndEndIterator>; /** * 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): UndEndNext>; /** * 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, end?: Point): UndEndNext>; pairs0(after: undefined | OverlayPoint, inclusive?: boolean): UndEndNext>; pairs(after?: undefined | OverlayPoint, inclusive?: boolean): IterableIterator>; tuples0(after: undefined | OverlayPoint, inclusive?: boolean): UndEndNext>; tuples(after?: undefined | OverlayPoint, inclusive?: boolean): IterableIterator>; /** * 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) => boolean): OverlayPoint | 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): Set>; /** * 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): Set>; /** * 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, endOnMarker?: number): [complete: Set, partial: Set, 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, direction: -1 | 1): boolean; /** ------------------------------------------------------ {@link Stateful} */ hash: number; private clear; refresh(slicesOnly?: boolean): number; readonly slices: Map, [start: OverlayPoint, end: OverlayPoint]>; 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; }