UNPKG

malwoden

Version:

![alt text](./coverage/badge-lines.svg) ![alt text](./coverage/badge-statements.svg) ![alt text](./coverage/badge-functions.svg) ![alt text](./coverage/badge-branches.svg)

51 lines (50 loc) 1.52 kB
/** * HeapPriorityQueue allows for push/pop based on an attribute * of the inserted objects. The heap based implementation * underneath has theoretic O(log(n)) insert/pop time and O(c) * peek time. * * Because the bubble up/down might not preserve order within * items of the same priority, the array-priority-queue can be * a better though slower choice in some cases. */ export declare class HeapPriorityQueue<T> { private heap; 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); private getPriority; private findParent; private getChildFunction; private bubbleUpwards; private bubbleDownwards; /** * 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; /** * Returns the number of items in the queue. * @returns - Number of items in the queue. */ size(): number; }