Installation
npm i @httpie/queue-datastructure
Usage
Using the queue data structure is pretty straightforward. The library exposes a Queue class and you need to create a queue instance. You can create a queue from existing data or an empty one:
const Queue = require('@httpie/queue-datastructure')
const queue = new Queue([ 1, 2, 3 ])
const queue = new Queue(1, 2, 3)
const queue = new Queue()
API
.enqueue(items)
Pushes new items to the end of the queue.
queue.enqueue(1)
queue.enqueue(2, 3)
queue.enqueue([ 4, 5, 6])
.dequeue()
Removes and returns the item which is up for processing. Returns undefined if the queue is empty.
queue.enqueue(1, 2, 3)
queue.size()
queue.dequeue()
queue.size()
.peek()
Returns the front item without removing it from the queue. Returns undefined if the queue is empty.
queue.enqueue(1, 2, 3)
queue.peek()
.size()
Returns the number of items in the queue.
queue.size()
queue.enqueue(1, 2)
queue.size()
.isEmpty()
Returns true if there are no items in the queue, false otherwise.
queue.isEmpty()
queue.enqueue(1)
queue.isEmpty()
.isNotEmpty()
Returns true if there are items in the queue, false when the queue is empty.
queue.isNotEmpty()
queue.enqueue(1)
queue.isNotEmpty()
.clear()
Removes all items from the queue.
queue.clear()
queue.size()
Contributing
- Create a fork
- Create your feature branch:
git checkout -b my-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request 🚀
License
MIT © httpie
httpiejs.com ·
GitHub @httpiejs ·
Twitter @httpiejs