Container of elements which grants access to the least item stored in logarithmic time. Insertion operation has logarithmic complexity as well.
new AdaptableHeapPriorityQueue()
/**
* Creates an instance of AdaptableHeapPriorityQueue.
*
* @param elements List of elements to create the new priority queue with.
* @param compare Comparison function for element search. Elements are compared as numbers by default.
*/
constructor(elements: K[] | [K, V][] = [], protected compare: CompareFunc<K> = compareAsNumbers)
length
length: number
Number of elements in the queue. This field is read only.
/**
* Removes the first element from the front of the queue and returns it.
* Throws an error if the queue is empty.
*
* @returns Removed element.
*/
dequeue(): T;
enqueue()
/**
* Adds element at the rear of the queue.
*
* @param element Element to add.
*/
enqueue(element: T): void;
getFirst()
/**
* Gets element from the front of the queue without its removal.
*
* @returns Queue element.
*/
getFirst(): T;
isEmpty()
isEmpty(): boolean
Running time O(1)
Checks whether the queue is empty or not.
Returns:
TRUE if the queue is empty, FALSE otherwise.
Examples:
import { SortedPriorityQueue } from 'ads-js/queues';
const queue = new SortedPriorityQueue();
queue.isEmpty(); // true
queue.enqueue(1);
queue.isEmpty(); // false
remove()
/**
* Removes element from the queue by locator and returns it. Throws an error if the queue is empty
* or the locator is not valid.
*
* @param locator Locator of the element.
* @returns Removed element.
*/
remove(locator: Locator<K | [K, V]>): K | [K, V];
update()
/**
* Updates element in the queue by locator. Throws an error if the locator is not valid.
*
* @param locator Locator of the element.
* @param element The element updatement.
*/
update(locator: Locator<K | [K, V]>, element: K | [K, V]): void;