gis-tools-ts
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
87 lines • 2.73 kB
TypeScript
import type { PriorityCompare } from './priorityQueue.js';
/**
* # Splay Tree Set
*
* ## Description
* A splay tree set is a self-balancing binary search tree that does not allow duplicate items.
* 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 { VectorSet } from 'gis-tools-ts';
*
* const vecSet = new VectorSet<number>([], (a, b) => a - b);
*
* // If the item already exists, the existing item will be returned otherwise
* // the new item will be both added and returned
* let item = vecSet.add(1);
* vecSet.add(2);
*
* console.log(vecSet.length); // 2
* // Get first and last items
* let firstitem = vecSet.first(); // 1
* let lastitem = vecSet.last(); // 2
* // check if a value exists
* console.log(vecSet.has(1)); // true
* // look for a value right before one provided
* console.log(vecSet.lastBefore(2)); // 1
* // look for a value right after one provided
* console.log(vecSet.firstAfter(1)); // 2
* ```
*
* ## Links
* - TODO!()
*/
export declare class VectorSet<T> {
#private;
private compare;
/** @param compare - compare function */
constructor(compare?: PriorityCompare<T>);
/** @returns - the number of items in the set */
get length(): number;
/**
* Add an item
* @param item - the item to add
* @returns - the added item OR if the item already exists, the existing item
*/
add(item: T): T;
/**
* Check if an item exists
* @param key - the item
* @returns - true if the item exists
*/
has(key: T): boolean;
/**
* Delete an item. Return the deleted item if it exists otherwise undefined
* @param key - the item
* @returns - the deleted item
*/
delete(key: T): T | undefined;
/**
* Get the first item
* @returns - the first item, undefined if the set is empty
*/
first(): T | undefined;
/**
* Get the last item
* @returns - the last item, undefined if the set is empty
*/
last(): T | undefined;
/**
* Get the last item in the set that is strictly smaller than item.
* Returns undefined if no item was not found.
* @param item - the item to compare against
* @returns - the last item before the comparison item provided
*/
lastBefore(item: T): T | undefined;
/**
* Get the first item in the set that is strictly larger than item.
* Returns undefined if no item was not found.
* @param item - the item to compare against
* @returns - the first item after the comparison item provided
*/
firstAfter(item: T): T | undefined;
}
//# sourceMappingURL=vectorSet.d.ts.map