@1771technologies/lytenyte-pro
Version:
Blazingly fast headless React data grid with 100s of features.
67 lines (66 loc) • 2.24 kB
TypeScript
import type { TreeParent, TreeRoot } from "../async-tree/+types.async-tree.js";
/**
* Represents a flattened range with start/end row indices and an associated path.
*/
export type FlattenedRange = {
/** Starting row index (inclusive) */
rowStart: number;
/** Ending row index (exclusive) */
rowEnd: number;
/** Path identifier for this range */
parent: TreeParent<any, any> | TreeRoot<any, any>;
};
/**
* Represents a node in a range tree, containing a range and its nested child ranges.
*/
export interface RangeNode {
/** The range associated with this node */
range: FlattenedRange;
/** Child nodes representing nested ranges within this range */
children: RangeNode[];
}
/**
* A tree structure for efficient nested range operations.
*
* Maintains a hierarchical representation of ranges where parent ranges contain their
* child ranges. Provides methods for querying ranges that contain specific row indices.
*
* @remarks
* The tree is constructed by:
* 1. Sorting ranges by start index
* 2. Using the first range as root
* 3. Inserting subsequent ranges into their appropriate parent nodes
*
* @example
* ```typescript
* const ranges = [
* { rowStart: 0, rowEnd: 100, path: 'root' },
* { rowStart: 20, rowEnd: 50, path: 'child1' },
* { rowStart: 30, rowEnd: 40, path: 'grandchild' }
* ];
*
* const tree = new RangeTree(ranges);
* const rangesAtRow25 = tree.findRangesForRowIndex(25);
* // Returns [root, child1]
* ```
*/
export declare class RangeTree {
/** Root node of the range tree */
root: RangeNode;
/**
* Creates a new range tree from an array of flattened ranges.
*
* @param ranges - Array of ranges to organize into a tree structure
*/
constructor(ranges: FlattenedRange[]);
/**
* Finds all ranges that contain the specified row index.
*
* Traverses the tree from root to leaves, collecting all ranges that contain
* the target index. Returns ranges in order from outermost to innermost.
*
* @param index - Row index to search for
* @returns Array of ranges containing the index, ordered from outer to inner
*/
findRangesForRowIndex(index: number): FlattenedRange[];
}