@rimbu/sorted
Version:
Immutable SortedMap and SortedSet implementations for TypeScript
41 lines (40 loc) • 1.64 kB
text/typescript
/**
* Utility namespace used by the sorted B‑tree implementations to encode
* positions within a node.<br/>
* <br/>
* Non‑negative values represent entry indices, while negative values
* represent child positions encoded using {@link SortedIndex.firstChild}
* and the {@link SortedIndex.next} / {@link SortedIndex.prev} helpers.
*/
export declare namespace SortedIndex {
/**
* Returns the next encoded index after the given `index`.<br/>
* <br/>
* The sequence walks over both entries and children inside a node in
* a consistent order and is used to traverse node contents.
* @param index - the current encoded index
*/
function next(index: number): number;
/**
* Returns the previous encoded index before the given `index`.<br/>
* <br/>
* Together with {@link SortedIndex.next} this allows iteration in
* both directions over entries and children within a node.
* @param index - the current encoded index
*/
function prev(index: number): number;
/**
* Encoded index representing the position of the first child inside a node.
* Used as a starting point when traversing children with
* {@link SortedIndex.next} / {@link SortedIndex.prev}.
*/
const firstChild = -1;
/**
* Compares two encoded indices and returns a negative number if `i1` comes
* before `i2`, a positive number if `i1` comes after `i2`, or `0` when
* they represent the same position.
* @param i1 - the first encoded index
* @param i2 - the second encoded index
*/
function compare(i1: number, i2: number): number;
}