A functional priority queue in JavaScript
MIT License
A confluently persistent functional priority queue.
This priority queue is implemented using a pairing heap, though because it uses a pure functional interface it does not support the decrease-key function (as locating a node within the heap without maintaining cyclic pointers is expensive).
var fpq = require('functional-priority-queue')
This module works in any node-flavored CommonJS environment, including node.js, iojs and browserify. You can install it using the npm package manager with the following command:
npm i functional-priority-queue
var fpq = require('functional-priority-queue')
var pq = fpq(keys, values)
Creates a new functional priority queue
keys
is an array of weights which are used to order the elements in the priority queuevalues
is an array of values which are ascoiated to the keysReturns A new priority queue
Time Complexity O(keys.length)
pq.minKey
The key of the smallest element in the priority queue
pq.minValue
The value of the smallest element in the priority queue
var next = fpq.push(pq, key, value)
Adds an item to the priority queue
pq
is the priority queue into which we are insertingkey
is the key we are inserting into the priority queuevalue
is the value we are inserting into the priority queueReturns A new priority queue with the pair (key, value)
added to it
Time Complexity O(1)
var next = fpq.pop(pq)
Removes the top element from a priority queue
pq
is a priority queue which we are removing fromReturns A copy of pq
with the minimal element deleted
Time Complexity O(log(n))
amortized
var next = fpq.merge(pq1, pq2, ...pqn)
Merges a list of priority queues into a single priority queue
pq1, pq2, ...pqn
is a list of n
priority queuesReturns A single priority queue whose contents are equal to all the input priority queues combined
Time Complexity O(n)
(c) 2015 Mikola Lysenko. MIT License