Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tomeraberbach/quetie

🎀 Just the cutest and tiniest queue/deque implementation!
https://github.com/tomeraberbach/quetie

amortized-array data-structures deque double-ended-queue npm-module npm-package queue stack

Last synced: 25 days ago
JSON representation

🎀 Just the cutest and tiniest queue/deque implementation!

Awesome Lists containing this project

README

        


quetie



version


CI


gzip size


brotli size


Sponsor


Just the cutest and tiniest queue/deque implementation!

## Features

- **Tiny:** ~360 bytes minzipped!
- **Fast:**
[amortized O(1) time complexity](https://en.wikipedia.org/wiki/Amortized_analysis)
for all operations
- **Tree Shakeable:** use `Queue` if you don't need a full `Deque`!

## Install

```sh
$ npm i quetie
```

## Usage

```js
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](https://github.com/TomerAberbach/quetie/blob/main/src/index.d.ts)
for more documentation.

## Contributing

Stars are always welcome!

For bugs and feature requests,
[please create an issue](https://github.com/TomerAberbach/quetie/issues/new).

For pull requests, please read the
[contributing guidelines](https://github.com/TomerAberbach/quetie/blob/master/contributing.md).

## License

[Apache 2.0](https://github.com/TomerAberbach/quetie/blob/master/license)

This is not an official Google product.