export declare class IntervalTree { private readonly _rangeMapper; private _tree; /** * @param rangeMapper Function that maps data to its interval bounds. */ constructor(rangeMapper: IntervalTreeRangeMapper); /** * Inserts a new interval into the tree. * * @param data The data to add to the tree. * * @timeComplexity `O(log(n))` * */ insert(data: T): void; /** * Deletes an interval from the tree. * * @param data The data whose interval is to be deleted from the tree. * * @timeComplexity `O(log(n))` */ delete(data: T): void; /** * Deletes values that doesn't meet the filter function condition. * * @param filterFunction A function that decides which values to delete. * It should return `false` if the value needs to be deleted, * otherwise `true`. * * @timeComplexity `O(n + k * log(n))` where `k` is the number of values * that doesn't meet the filter function condition. * * @retuns An array of intervals that has been deleted. */ filter(filterFunction: (value: T) => boolean): T[]; /** * Deletes values that overlap within provided range. * * @param lower The lower bound of the range. * @param upper The upper bound of the range. * @param inclusive Set to `true` to include intervals that doesn't * overlap but touch the given lower or upper bound. Default is `false`. * * @timeComplexity `O(n + k * log(n))` where `k` is the number of values * that is getting deleted. * * @retuns An array of intervals that has been deleted. */ deleteInRange(lower: number, upper: number, inclusive?: boolean): T[]; /** * Queries all intervals that overlap with the provided range. * * @param lower The lower bound of the range. * @param upper The upper bound of the range. * @param inclusive Set to `true` to include intervals that doesn't * overlap but touch the given lower or upper bound. Default is `false`. * * @timeComplexity `O(k + log(n))` where `k` is the number of intervals * that overlap within the given range. * * @returns Array of data whose intervals overlap with the range. */ query(lower: number, upper: number, inclusive?: boolean): T[]; /** * Checks whether any intervals overlap with the provided range. * * @param lower The lower bound of the range. * @param upper The upper bound of the range. * @param inclusive Set to `true` to check intervals that doesn't * overlap but touch the given lower or upper bound. Default is `false`. * * @timeComplexity `O(log(n))` * * @returns True if any interval overlaps with the given range, * otherwise false. */ hasOverlap(lower: number, upper: number, inclusive?: boolean): boolean; /** * Clears the tree. * * @timeComplexity `O(1)` */ clear(): void; /** * Returns the number of intervals stored in the tree. * * @timeComplexity `O(1)` * * @returns The number of intervals. */ size(): number; /** * Checks if the interval tree is empty. * * @timeComplexity `O(1)` * * @returns True if the tree is empty, otherwise false. */ isEmpty(): boolean; /** * Creates a shallow clone of the interval tree. * * @timeComplexity `O(n)` * * @returns A new cloned instance of the interval tree. */ clone(): IntervalTree; /** * Same as `query` but it uses a generator. * * @param lower The lower bound of the range. * @param upper The upper bound of the range. * @param inclusive Set to `true` to include intervals that doesn't * overlap but touch the given lower or upper bound. Default is `false`. * * @timeComplexity `O(k + log(n))` where `k` is the number of intervals * that overlap within the given range. * * @yields The data of intervals overlapping with the range. */ rangeQuery(lower: number, upper: number, inclusive?: boolean): Generator; values(): Generator; [Symbol.iterator](): Generator; /** * Constructs an interval tree from an array of data. * * @param array The array of data. * @param rangeMapper The function to map each data item to its interval. * * @timeComplexity `O(n * log(n))` * * @returns The newly constructed interval tree. */ static fromArray(array: T[], rangeMapper: IntervalTreeRangeMapper): IntervalTree; /** * Recomputes the max upper bound of each node in the path to the given data. * * @param data The data for which to recompute the max upper bound. * * @timeComplexity `O(log(n))` */ private _recomputeMaxUpperBound; /** * Traverses the tree to find the node associated with the provided data. * @param data The data to traverse to. * * @timeComplexity `O(log(n))` * * @yields Nodes along the path to the target node. */ private _traverseTo; } export type IntervalTreeRangeMapper = (data: T) => [number, number];