thorish
Version:
This is a library of useful JS concepts and data structures for Node and the browser. It it, unashamedly, a dumping ground for code needed by [@samthor](https://twitter.com/samthor)'s projects.
64 lines (63 loc) • 1.57 kB
TypeScript
/**
* AATree implementation.
*
* Obviously `O(logn)` performance, but scales linearly under performance testing.
* (Future readers: don't look here for perf gains.)
*
* https://en.wikipedia.org/wiki/AA_tree
*/
export declare class AATree<X extends F, F = X> {
private compare;
private root;
private _count;
private _change;
constructor(compare: (a: F, b: F) => number);
/**
* Clones this {@link AATree} using {@link structuredClone}.
*/
clone(): AATree<X, F>;
clear(): void;
/**
* The count of items in this tree.
*/
count(): number;
/**
* Query for this exact node.
*/
query(data: F): X | undefined;
/**
* Finds the target node or the node closest before the query.
*/
equalBefore(data: F): X | undefined;
/**
* Finds the node immediately before the query.
*/
before(data: F): X | undefined;
/**
* Finds the target node or the node closest after the query.
*/
equalAfter(data: F): X | undefined;
/**
* Finds the node immediately after the query.
*/
after(data: F): X | undefined;
/**
* Inserts the value. Updates the previous value if compare is zero.
*
* @return if there was a change
*/
insert(data: X): boolean;
/**
* Removes the value.
*
* @return if there was a change
*/
remove(data: F): boolean;
private skew;
private split;
private _equalBefore;
private _equalAfter;
private _insert;
private _remove;
private _findMin;
}