@foxglove/avl
Version:
Adelson-Velsky-Landis (AVL) self-balancing binary trees in TypeScript
91 lines • 2.57 kB
TypeScript
/**
* Implements a Adelson-Velsky-Landis (AVL) tree, a self-balancing binary tree.
* Lookup, insertion, and deletion all take O(log n) time in both the average
* and worst cases, where n is the number of nodes in the tree prior to the
* operation.
*/
export declare class AVLTree<K, V> {
private readonly _comparator;
private _root?;
private _size;
constructor(comparator?: (a: K, b: K) => number);
/**
* Number of nodes
*/
get size(): number;
/**
* Clear the tree
* @return {AVLTree}
*/
clear(): AVLTree<K, V>;
/**
* Whether the tree contains a node with the given key
*/
has(key: K): boolean;
/**
* Returns all keys in order
*/
keys(): IterableIterator<K>;
/**
* Returns all values in order
*/
values(): IterableIterator<V>;
/**
* Returns all key/value pairs in order
*/
entries(): IterableIterator<[K, V]>;
/**
* Returns the entry with the minimum key
*/
minEntry(): [K, V] | undefined;
/**
* Returns the entry with the maximum key
*/
maxEntry(): [K, V] | undefined;
/**
* Minimum key
*/
minKey(): K | undefined;
/**
* Maximum key
*/
maxKey(): K | undefined;
/**
* Removes and returns the entry with smallest key
*/
shift(): [K, V] | undefined;
/**
* Removes and returns the entry with largest key
*/
pop(): [K, V] | undefined;
/**
* Search for an entry by key
*/
get(key: K): V | undefined;
/**
* Execute a callback for each key/value entry in order
*/
forEach(callbackfn: (value: V, key: K, tree: AVLTree<K, V>) => void): AVLTree<K, V>;
/**
* Walk key range from `low` to `high` in order
*/
range(low: K, high: K, callbackfn: (value: V, key: K, tree: AVLTree<K, V>) => void): AVLTree<K, V>;
findLessThan(key: K): [K, V] | undefined;
findLessThanOrEqual(key: K): [K, V] | undefined;
findGreaterThan(key: K): [K, V] | undefined;
findGreaterThanOrEqual(key: K): [K, V] | undefined;
private findGreaterThanOrEqualNode;
/**
* Insert a new key/value pair into the tree or update an existing entry
*/
set(key: K, value: V): this;
/**
* Finds the first matching node by key and removes it
*/
delete(key: K): boolean;
/**
* Returns a string representation of the tree - primitive horizontal print-out
*/
toString(printEntry?: (entry: [K, V]) => string): string;
}
//# sourceMappingURL=AVLTree.d.ts.map