Just the cutest and tiniest queue/deque implementation!
- Tiny: ~360 bytes minzipped!
- Fast: amortized O(1) time complexity for all operations
- Tree Shakeable: use
Queue
if you don't need a fullDeque
!
$ npm i quetie
import { Deque, Queue } from 'quetie'
const queue = new Queue()
queue.push(1)
queue.push(2)
queue.push(3)
console.log(queue.size)
//=> 3
console.log(queue.at(0))
console.log(queue.at(1))
console.log(queue.at(2))
console.log(queue.at(3))
console.log(queue.at(-1))
//=> 1
//=> 2
//=> 3
//=> 1
//=> 3
console.log([...queue])
//=> [ 1, 2, 3 ]
console.log(queue.shift())
console.log(queue.shift())
console.log(queue.shift())
console.log(queue.shift())
//=> 1
//=> 2
//=> 3
//=> undefined
const deque = new Deque()
deque.push(1)
deque.push(2)
deque.push(3)
deque.unshift(0)
console.log(deque.size)
//=> 4
console.log(deque.at(0))
console.log(deque.at(1))
console.log(deque.at(2))
console.log(deque.at(3))
console.log(deque.at(-1))
//=> 0
//=> 1
//=> 2
//=> 3
//=> 3
console.log([...deque])
//=> [ 0, 1, 2, 3 ]
console.log(deque.pop())
console.log(deque.shift())
console.log(deque.shift())
console.log(deque.pop())
console.log(deque.pop())
//=> 3
//=> 0
//=> 1
//=> 2
//=> undefined
See the type definitions for more documentation.
Stars are always welcome!
For bugs and feature requests, please create an issue.
For pull requests, please read the contributing guidelines.
This is not an official Google product.