UNPKG

avl

Version:

Fast AVL tree for Node and browser

134 lines (130 loc) 2.92 kB
// Generated by dts-bundle-generator v9.5.1 export interface AVLNode<K, V> { parent: AVLNode<K, V> | null; left: AVLNode<K, V> | null; right: AVLNode<K, V> | null; balanceFactor: number; key: K; data?: V; } /** Callback for comparator */ export type Comparator<K> = (a: K, b: K) => number | 1 | 0 | -1; export type Visitor<K, V> = (node: AVLNode<K, V>, i: number) => void; export type NodeCallback<K, V, T = unknown> = (this: T | undefined, node: AVLNode<K, V>) => void | boolean; export type NodePrinter<K, V> = (node: AVLNode<K, V>) => string; export declare class AVLTree<K = number, V = unknown> { private _comparator; private _root; private _size; private _noDuplicates; constructor(comparator?: Comparator<K>, noDuplicates?: boolean); /** * Clear the tree */ destroy(): this; /** * Clear the tree * @return {AVLTree} */ clear(): this; /** * Number of nodes * @return {number} */ get size(): number; get root(): AVLNode<K, V> | null; /** * Whether the tree contains a node with the given key */ contains(key: K): boolean; /** * Successor node */ next(node: AVLNode<K, V>): AVLNode<K, V> | null; /** * Predecessor node */ prev(node: AVLNode<K, V>): AVLNode<K, V> | null; /** * @param {forEachCallback} callback * @return {AVLTree} */ forEach(callback: Visitor<K, V>): this; /** * Walk key range from `low` to `high`. Stops if `fn` returns a value. * @param {Key} low * @param {Key} high * @param {Function} fn * @param {*?} ctx * @return {SplayTree} */ range<T>(low: K, high: K, fn: NodeCallback<K, V, T>, ctx?: T): this; /** * Returns all keys in order */ keys(): K[]; /** * Returns `data` fields of all nodes in order. */ values(): V[]; /** * Returns node at given index */ at(index: number): AVLNode<K, V> | null; /** * Returns node with the minimum key */ minNode(): AVLNode<K, V> | null; /** * Returns node with the max key */ maxNode(): AVLNode<K, V> | null; /** * Min key */ min(): K | null; /** * Max key */ max(): K | null; /** * @return {boolean} true/false */ isEmpty(): boolean; /** * Removes and returns the node with smallest key */ pop(): AVLNode<K, V> | null; /** * Removes and returns the node with highest key */ popMax(): AVLNode<K, V> | null; /** * Find node by key */ find(key: K): AVLNode<K, V> | null; /** * Insert a node into the tree */ insert(key: K, data?: V): AVLNode<K, V> | null; /** * Removes the node from the tree. If not found, returns null. */ remove(key: K): K | null; /** * Bulk-load items */ load(keys?: K[], values?: V[], presort?: boolean): this; /** * Returns true if the tree is balanced */ isBalanced(): boolean; /** * String representation of the tree - primitive horizontal print-out */ toString(printNode?: NodePrinter<K, V>): string; } export { AVLTree as Tree, }; export {};