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')
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 keys
Returns A new priority queue
Time Complexity O(keys.length)
The key of the smallest element in the priority queue
The value of the smallest element in the priority queue
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 queue
Returns A new priority queue with the pair (key, value)
added to it
Time Complexity O(1)
Removes the top element from a priority queue
pq
is a priority queue which we are removing from
Returns A copy of pq
with the minimal element deleted
Time Complexity O(log(n))
amortized
Merges a list of priority queues into a single priority queue
pq1, pq2, ...pqn
is a list ofn
priority queues
Returns 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