Stability: 1 - Experimental
Priority queue.
npm install priority-heap-queue
npm test
var PriorityQueue = require('priority-heap-queue');
var maxQueue = new PriorityQueue();
var minQueue = new PriorityQueue({kind: 'min'});
TODO
A JavaScript implementation of a priority queue using heap data structure.
WARNING: This implementation uses 1-indexed arrays (instead of 0-indexed) arrays.
array
: Array 1-indexed array storing the heap structureindex
: Integer index of the key to decreasevalue
: Integer the value to decrease the key to
Sets the value of the key at index
to value
and ensures heap property is maintained as a result.
array
: Array 1-indexed array storing the heap structureindex
: Integer index of the key to increasevalue
: Integer the value to increase the key to
Sets the value of the key at index
to value
and ensures heap property is maintained as a result.
array
: Array 1-indexed array storing the heap structureindex
: Integer the array index to start maxHeapify procedure onheapSize
: Integer heap size
Ensures that the max-heap property is satisfied for the sub-tree rooted at index
of the array representing a binary tree.
array
: Array 1-indexed array storing the heap structureindex
: Integer the array index to start maxHeapify procedure onheapSize
: Integer heap size
Ensures that the min-heap property is satisfied for the sub-tree rooted at index
of the array representing a binary tree.
options
:kind
: String One ofmin
,max
(default:max
)
Creates a new PriorityQueue.
index
: Integer index of the key to decreasevalue
: Integer the value to decrease the key to
Sets the value of the key at index
to value
and ensures heap property is maintained as a result.
Removes and returns the element with the largest key.
Removes and returns the element with the smallest key.
index
: Integer index of the key to increasevalue
: Integer the value to increase the key to
Sets the value of the key at index
to value
and ensures heap property is maintained as a result.
key
: Integer key of the element to be insertedelement
: Any element to associate with the key
Inserts the element
into the priority queue at the specified key
.
Returns the element with the largest key. The element is not removed.
Returns the element with the smallest key. The element is not removed.