UNPKG

dastal

Version:

Data Structures & Algorithms implementations

44 lines (43 loc) 1.41 kB
import { CombineFn } from '..'; import { SegmentTree } from './segmentTree'; /** * A {@link SegmentTree} internally represented by a binary tree array, with nodes stored in in-order traversal. * * Memory usage: n elements require 2n - 1 space. * */ export declare class InOrderSegmentTree<T> implements SegmentTree<T> { /** * The set of elements and aggregation nodes for the tree */ protected array: T[]; /** * The function used to aggregate elements */ protected combine: CombineFn<T>; /** * Construct a new segment tree * * @param combine - The function used to aggregate segment information * @param elements - A set of elements to add into the initial tree */ constructor(combine: CombineFn<T>, elements?: Iterable<T>); clear(): void; pop(): T | undefined; push(element: T): number; query(min: number, max: number): T; get size(): number; /** * Return an iterator through the tree's elements */ [Symbol.iterator](): Iterator<T>; update(min: number, max: number, operation: (element: T, index: number) => T): void; /** * A helper method to update complete aggregation nodes for an index. * * @params index - The index whose aggregation nodes will be updated. * * @returns - The top aggregation node's new value. */ protected aggregate(index: number): T; }