UNPKG

dastal

Version:

Data Structures & Algorithms implementations

63 lines (62 loc) 1.89 kB
import { Collection } from 'src/collection/collection'; import { CombineFn } from '..'; import { SegmentTree } from './segmentTree'; /** * A {@link SegmentTree} with entries stored in level-order traversal. * * Memory usage: n elements require n - 1 + 2**(⌊log<sub>2</sub>(n-1)⌋ + 1) space. * */ export declare class LevelOrderSegmentTree<T> implements SegmentTree<T> { /** * The internal array used to store elements and aggregation nodes */ protected array: Array<T>; /** * The function used to aggregate elements */ protected combine: CombineFn<T>; /** * The used length (size) of our internal array */ protected length: number; /** * The start index for the lowest level */ protected level: number; /** * Construct a new {@link SegmentTree} * * @param combinFn - The function used to aggregate elements * @param elements - Initial elements to build into the 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 elements */ [Symbol.iterator](): Iterator<T>; update(min: number, max: number, operation: (element: T, index: number) => T): void; /** * A helper method to aggregate a range of elements */ protected aggregate(min: number, max: number): void; /** * A helper method used to build the tree * * @param elements The initial set of elements to add into the tree */ protected build(elements: Collection<T> | Iterable<T>): void; /** * Shift the tree down a level */ protected grow(): void; /** * Shift the tree to the highest non-full level */ protected shrink(): void; }