Queue Data Structure Implementation. Use it for large arrays.
Explore the docs »
·
Report Bug
·
Request Feature
# Import Package
const Queue = require("sumo-queue");
const queue = new Queue(2);
// OUTPUT: 1609158613385wbQvkB5djUXB debug log: A new queue 1609158613385wbQvkB5djUXB is initialized with capacity 2
queue.enqueue(1);
// OUTPUT: 1609158613385wbQvkB5djUXB debug log: Node added {"currentPointerValue":1,"nextPointer":null}
console.log(queue.iterate());
// OUTPUT: [ 1 ]
console.log(queue.size);
// OUTPUT: 1
queue.bulkEnqueue([2, 3]);
/* OUTPUT:
1609158613385wbQvkB5djUXB debug log: Node added {"currentPointerValue":2,"nextPointer":null}
1609158613385wbQvkB5djUXB debug log: Queue is full
*/
console.log(queue.iterate());
// OUTPUT: [ 1, 2 ]
console.log(queue.size);
// OUTPUT: 2
console.log(queue.first());
/* OUTPUT:
SumoNode {
currentPointerValue: 1,
nextPointer: SumoNode { currentPointerValue: 2, nextPointer: null }
}
*/
console.log(queue.first().currentPointerValue);
// OUTPUT: 1
console.log(queue.last());
/* OUTPUT:
SumoNode { currentPointerValue: 2, nextPointer: null }
*/
console.log(queue.isEmpty());
// OUTPUT: false
console.log(queue.isFull());
// OUTPUT: true
Table of Contents
In computer science, a queue is a collection of entities that are maintained in a sequence and can be modified by the addition of entities at one end of the sequence and the removal of entities from the other end of the sequence. (Wikipedia).
When you are dealing with larger arrays, it's always suggested to use Queue, because of constant time complexity O(1).
Sumo Queue has all the queue operations implemented. Use it especially for the larger array to attain O(1) complexity.
This package is built with raw javascript and Mocha / Chai is used for testing.
Install this package and follow examples given below. We have examples
folder which has implementation code as well.
- Install NPM packages
npm i --save sumo-queue
Once this package is added in your project as mentioned in the installation
, you need to import this package and create a QUEUE
class to start using it.
# Import Package
const Queue = require("sumo-queue");
const queue = new Queue(2);
// OUTPUT: 1609158613385wbQvkB5djUXB debug log: A new queue 1609158613385wbQvkB5djUXB is initialized with capacity 2
queue.enqueue(1);
// OUTPUT: 1609158613385wbQvkB5djUXB debug log: Node added {"currentPointerValue":1,"nextPointer":null}
console.log(queue.iterate());
// OUTPUT: [ 1 ]
console.log(queue.size);
// OUTPUT: 1
queue.bulkEnqueue([2, 3]);
/* OUTPUT:
1609158613385wbQvkB5djUXB debug log: Node added {"currentPointerValue":2,"nextPointer":null}
1609158613385wbQvkB5djUXB debug log: Queue is full
*/
console.log(queue.iterate());
// OUTPUT: [ 1, 2 ]
console.log(queue.size);
// OUTPUT: 2
console.log(queue.first());
/* OUTPUT:
SumoNode {
currentPointerValue: 1,
nextPointer: SumoNode { currentPointerValue: 2, nextPointer: null }
}
*/
console.log(queue.first().currentPointerValue);
// OUTPUT: 1
console.log(queue.last());
/* OUTPUT:
SumoNode { currentPointerValue: 2, nextPointer: null }
*/
console.log(queue.isEmpty());
// OUTPUT: false
console.log(queue.isFull());
// OUTPUT: true
Test cases is written in test/test.js
. To test this package, run npm run test
.
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
SANKET MAKHIJA - @sanket_dude - sanket[dot]mahija[at]gmail[dot]com
Consider sponsoring this package and help open source community and contributions.