spque
v1.1.2
Published
datastructures: simple and fast queue and priority queue
Downloads
8
Readme
//Queue
var Queue = require('spque').Queue
let q = new Queue
q.put(2)
q.put(4)
console.log(
q.size, q.get()
)
//2 2
//Stack
var Stack = require('spque').Stack
let q = new Stack
q.put(2)
q.put(4)
console.log(
q.size, q.get()
)
//2 4
//Priority Queue
var PQueue = require('spque').PQueue
let q = new PQueue
q.put(2)
q.put(4)
console.log(
q.size, q.get()
)
//2 4
let mypq = new (require('spque').PQueue)()
mypq.comparator = (a, b) =>
a.toUpperCase()
.localeCompare(
b.toUpperCase()
)
mypq.put('I')
mypq.put('want')
mypq.put('to')
mypq.put('break')
mypq.put('free')
while (mypq.size)
console.log(mypq.get())
Test:
var PQueue = require('spque').PQueue_min
let q = new PQueue
let most
for (i=0;i<100000;i++) q.put( Math.round( Math.random()*1000000000 ) )
console.log(q.size);
let elozo=1
while (q.size) {
if ( elozo >= (most = q.get() ) ) console.log('equal or mistake',most,elozo);
elozo=most
}