gis-tools-ts
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
65 lines • 2.16 kB
TypeScript
/**
* # FlatQueue
*
* ## Description
* A priority queue implemented using a binary heap.
*
* A Typescript port from the [flatqueue](https://github.com/mourner/flatqueue) code.
*
* ## Usage
*
* ```ts
* import { FlatQueue } from 'gis-tools-ts';
*
* const queue = new FlatQueue<number>();
*
* queue.push(0, 2);
* queue.push(1, 1);
* queue.push(2, 3);
*
* expect(queue.pop()).toEqual(2);
* expect(queue.pop()).toEqual(1);
* expect(queue.pop()).toEqual(0);
* ```
*/
export declare class FlatQueue<T = number> {
#private;
/** @returns - the number of items */
get length(): number;
/** Removes all items from the queue. */
clear(): void;
/**
* Adds `item` to the queue with the specified `priority`.
*
* `priority` must be a number. Items are sorted and returned from low to high priority. Multiple items
* with the same priority value can be added to the queue, but there is no guaranteed order between these items.
* @param item - the item to add
* @param priority - the priority of the item
*/
push(item: T, priority: number): void;
/**
* Removes and returns the item from the head of this queue, which is one of
* the items with the lowest priority. If this queue is empty, returns `undefined`.
* @returns the item from the head of this queue
*/
pop(): T | undefined;
/**
* @returns the item from the head of this queue without removing it. If this queue is empty,
* returns `undefined`.
*/
peek(): T | undefined;
/**
* @returns the priority value of the item at the head of this queue without
* removing it. If this queue is empty, returns `undefined`.
*/
peekValue(): number | undefined;
/**
* Shrinks the internal arrays to `this.length`.
*
* `pop()` and `clear()` calls don't free memory automatically to avoid unnecessary resize operations.
* This also means that items that have been added to the queue can't be garbage collected until
* a new item is pushed in their place, or this method is called.
*/
shrink(): void;
}
//# sourceMappingURL=flatqueue.d.ts.map