gis-tools-ts
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
87 lines • 2.74 kB
TypeScript
import type { PriorityCompare } from './priorityQueue';
/** A basic node for a splay tree */
declare class SplayTreeNode<T> {
readonly key: T;
left?: SplayTreeNode<T>;
right?: SplayTreeNode<T>;
/** @param key - the element to store */
constructor(key: T);
}
/**
* # Splay Tree Set
*
* ## Description
* A splay tree set is a self-balancing binary search tree that does not allow duplicate elements.
* The value of a splay tree is in it's amortized O(log n) for all insert, delete min/max,
* and find min/max operations.
*
* ## Usage
*
* ```ts
* import { SplayTreeSet } from 'gis-tools-ts';
*
* const tree = new SplayTreeSet<number>([], (a, b) => a - b);
*
* tree.add(1);
* tree.add(2);
*
* const current = tree.peek(); // 1
* console.log(tree.length); // 2
* let next = tree.pop(); // 1
* console.log(tree.length); // 1
* next = tree.pop(); // 2
* console.log(tree.length); // 0
* ```
*/
export declare class SplayTreeSet<T> {
#private;
private compare;
/** @param compare - compare function */
constructor(compare?: PriorityCompare<T>);
/** @returns - the number of elements in the tree */
get length(): number;
/**
* Add an element
* @param element - the element to add
* @returns - the added element OR if the element already exists, the existing element
*/
add(element: T): T | undefined;
/**
* Check if an element exists
* @param key - the element
* @returns - true if the element exists
*/
has(key: T): boolean;
/**
* Delete an element. Return the deleted element if it exists otherwise undefined
* @param key - the element
* @returns - the deleted element
*/
delete(key: T): SplayTreeNode<T> | undefined;
/**
* Get the first element
* @returns - the first element, undefined if the queue is empty
*/
first(): T | undefined;
/**
* Get the last element
* @returns - the last element, undefined if the queue is empty
*/
last(): T | undefined;
/**
* Get the last element in the set that is strictly smaller than element.
* Returns undefined if no element was not found.
* @param element - the element to compare against
* @returns - the last element before the comparison element provided
*/
lastBefore(element: T): T | undefined;
/**
* Get the first element in the set that is strictly larger than element.
* Returns undefined if no element was not found.
* @param element - the element to compare against
* @returns - the first element after the comparison element provided
*/
firstAfter(element: T): T | undefined;
}
export {};
//# sourceMappingURL=splayTree.d.ts.map