Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sanmak/sumo-queue
Queue Data Structure Implementation. Use it for large arrays.
https://github.com/sanmak/sumo-queue
array arrays chai complexity complexity-analysis data-structures javascript mocha mocha-chai queue queue-algorithm queues
Last synced: 15 days ago
JSON representation
Queue Data Structure Implementation. Use it for large arrays.
- Host: GitHub
- URL: https://github.com/sanmak/sumo-queue
- Owner: sanmak
- License: mit
- Created: 2020-12-28T10:09:04.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2020-12-29T15:48:28.000Z (almost 4 years ago)
- Last Synced: 2024-10-10T18:43:09.004Z (about 1 month ago)
- Topics: array, arrays, chai, complexity, complexity-analysis, data-structures, javascript, mocha, mocha-chai, queue, queue-algorithm, queues
- Language: JavaScript
- Homepage: http://boxpiper.com/
- Size: 16.6 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# sumo-queue
SUMO QUEUE
Queue Data Structure Implementation. Use it for large arrays.
Explore the docs »
·
Report Bug
·
Request Feature
## Dead Simple to Use
```javascript
# Import Package
const Queue = require("sumo-queue");const queue = new Queue(2);
// OUTPUT: 1609158613385wbQvkB5djUXB debug log: A new queue 1609158613385wbQvkB5djUXB is initialized with capacity 2queue.enqueue(1);
// OUTPUT: 1609158613385wbQvkB5djUXB debug log: Node added {"currentPointerValue":1,"nextPointer":null}console.log(queue.iterate());
// OUTPUT: [ 1 ]console.log(queue.size);
// OUTPUT: 1queue.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: 2console.log(queue.first());
/* OUTPUT:
SumoNode {
currentPointerValue: 1,
nextPointer: SumoNode { currentPointerValue: 2, nextPointer: null }
}
*/console.log(queue.first().currentPointerValue);
// OUTPUT: 1console.log(queue.last());
/* OUTPUT:
SumoNode { currentPointerValue: 2, nextPointer: null }
*/console.log(queue.isEmpty());
// OUTPUT: falseconsole.log(queue.isFull());
// OUTPUT: true```
Table of Contents
## About The Package
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.
### Built With
This package is built with raw javascript and Mocha / Chai is used for testing.
* [Javascript](https://www.javascript.com/)
* [Mocha](https://mochajs.org/)
* [Chai](https://www.chaijs.com/)## Getting Started
Install this package and follow examples given below. We have `examples` folder which has implementation code as well.
### Installation1. Install NPM packages
```sh
npm i --save sumo-queue
```## Usage
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.
## Eg:
```javascript
# Import Package
const Queue = require("sumo-queue");const queue = new Queue(2);
// OUTPUT: 1609158613385wbQvkB5djUXB debug log: A new queue 1609158613385wbQvkB5djUXB is initialized with capacity 2queue.enqueue(1);
// OUTPUT: 1609158613385wbQvkB5djUXB debug log: Node added {"currentPointerValue":1,"nextPointer":null}console.log(queue.iterate());
// OUTPUT: [ 1 ]console.log(queue.size);
// OUTPUT: 1queue.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: 2console.log(queue.first());
/* OUTPUT:
SumoNode {
currentPointerValue: 1,
nextPointer: SumoNode { currentPointerValue: 2, nextPointer: null }
}
*/console.log(queue.first().currentPointerValue);
// OUTPUT: 1console.log(queue.last());
/* OUTPUT:
SumoNode { currentPointerValue: 2, nextPointer: null }
*/console.log(queue.isEmpty());
// OUTPUT: falseconsole.log(queue.isFull());
// OUTPUT: true```
## Test
Test cases is written in `test/test.js`. To test this package, run `npm run test`.
## Roadmap
See the [open issues](https://github.com/sanmak/sumo-queue/issues) for a list of proposed features (and known issues).
## Contributing
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**.
1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request## License
Distributed under the MIT License. See `LICENSE` for more information.
## 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.