1.0.1 • Published 2 years ago
@rayeeskm/queue v1.0.1
Simple Performant Queue in JS
The general way of implementing queue in javascript is to utilize the push and shift function on arrays. Though push function is straight forward, shift executes at a cost of rewriting the whole array. the cost becomes pretty evident once the queue size goes upwards of 10000.
This queue implementation is a simple straight forward mechanism of linking each element in a queue ensuring cost remains O(1)
Installation
npm install @rayeeskm/queue
Usage
import Queue from '@rayeeskm/queue';
// Create a Queue
q = new Queue()
// Add an element to queue
q.enQ(1)
// Fetch an element from queue
let val = q.deQ()
// Fetch the element but not remove from queue
val = q.peek()
// Get the size of the queue
let size = q.size()