malwoden
Version:
   
46 lines (45 loc) • 1.4 kB
TypeScript
/**
* ArrayPriorityQueue allows for push/pop based on an attribute
* of the inserted objects. The array based implementation
* underneath has theoretic O(c) insert time, and O(n)
* peek/pop time.
*
* Though this is slower in many cases than the heap based implementation,
* it preserves the order better and can result in more 'normal' paths
* when used with pathfinding.
*/
export declare class ArrayPriorityQueue<T> {
private data;
private priorityFunc;
/**
* @param priorityFunc - A function that takes the a value that
* has previously been inserted, and returns a priority.
*
* A lower score is higher priority.
*
* Ex. (monster) => monster.speed
*/
constructor(priorityFunc: (t: T) => number);
/**
* Insert data into the queue
* @param data - The data to insert
*/
insert(data: T): void;
/**
* Get the item with the lowest priority score,
* removing it from the queue.
* @returns - The lowest priority item
*/
pop(): T | undefined;
/**
* Get the item with the lowest priotity score,
* WITHOUT removing it.
* @returns - The lowest priority item
*/
peek(): T | undefined;
/**
* Returns the number of items in the queue.
* @returns - Number of items in the queue.
*/
size(): number;
}