Sumo-Queue: Queue Data Structure Implementation in JavaScript
Tags: javascript, github, webdev, npm
Published: 2020-12-28 17:34:07


> 
As per Wikipedia, 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.

The Queue is a data structure following the FIFO(First In, First Out) principle. When you are dealing with larger arrays, it's always suggested to use Queue, because of constant time complexity O(1).

The process of adding in a queue is known as Enqueue and removal is known as Dequeue. Front and Back signifies element at those respective positions. The queue capacity is known at the time of initialisation and it's the max number of elements a queue can hold.

![queue-and-its-basic-operations-operations-9bfc0ef1b53c11f9.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1609175214531/mwMxqbg7u.png)

With all the available information about queue and knowledge of JavaScript, pushed me to write a tiny package which implements this with almost simplicity.

Thus I wrote a code, named it **SUMO QUEUE**, pushed it to [GitHub](https://github.com/sanmak/sumo-queue/) and published to [NPM](https://www.npmjs.com/package/sumo-queue). Do check it out.



![github-npm.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1609176711172/jsfKZDHVH.jpeg)

GitHub: https://github.com/sanmak/sumo-queue/

NPM: https://www.npmjs.com/package/sumo-queue

## SUMO QUEUE

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.

### Installation and Usage


```javascript
npm i --save sumo-queue
``` 

```javascript
# Import Package
const Queue = require("sumo-queue");
```

```javascript
# Initialisation
const queue = new Queue(2);
// OUTPUT: 1609158613385wbQvkB5djUXB debug log: A new queue 1609158613385wbQvkB5djUXB is initialized with capacity 2

```

```javascript
# Enqueue operation
queue.enqueue(1);
// OUTPUT: 1609158613385wbQvkB5djUXB debug log: Node added {"currentPointerValue":1,"nextPointer":null}

```

```javascript
# Iteration
console.log(queue.iterate());
// OUTPUT: [ 1 ]
```

```javascript
# To get first element value
console.log(queue.first().currentPointerValue);
// OUTPUT: 1
```

There is a lot of features offered by this package. Check the [readme](https://github.com/sanmak/sumo-queue/blob/main/README.md) for more information. https://github.com/sanmak/sumo-queue/blob/main/README.md

## Open Source Contribution

I have mentioned that it's open for contribution and feel free to add new features. Contributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

## License

This package is distributed under MIT [license](https://github.com/sanmak/sumo-queue/blob/main/LICENSE).

<!-- CONTACT -->
## Contact

SANKET MAKHIJA - [@sanket_dude](https://twitter.com/sanket_dude) - sanket[dot]mahija[at]gmail[dot]com

## Sponsor ❤️

Consider sponsoring this package and help open source community and contributions.

 <a href="https://ko-fi.com/E1E72C2MM" target="_blank"> <img style={kofiStyle} src="https://cdn.ko-fi.com/cdn/kofi1.png?v=2"></img> </a>

## To read interesting topics, follow and read <a href="https://boxpiper.com/">BoxPiper blog</a>. 

Tech, Product, Money, Books, Life. Box Piper to serve you faster, easier and superior knowledge.