Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/annoraaq/parrot-queue
https://github.com/annoraaq/parrot-queue
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/annoraaq/parrot-queue
- Owner: Annoraaq
- Created: 2019-06-11T18:24:10.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T23:56:05.000Z (almost 2 years ago)
- Last Synced: 2024-11-27T21:13:58.723Z (26 days ago)
- Language: JavaScript
- Size: 729 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# parrot-queue
An efficient queue in JavaScript. Note that using native arrays as a queue
leads to O(n) runtime complexity for dequeuing, because shift takes O(n) in
the worst case.## Usage
```
const ParrotQueue = require("parrot-queue");const cinemaQueue = ParrotQueue();
cinemaQueue.enqueue('Clara');
cinemaQueue.enqueue('Peter');
cinemaQueue.enqueue('Lisa');
cinemaQueue.enqueue('John');console.log(cinemaQueue.size()) // "4"
console.log(cinemaQueue.peek()) // "Clara"
console.log(cinemaQueue.dequeue()) // "Clara"
console.log(cinemaQueue.dequeue()) // "Peter"
console.log(cinemaQueue.dequeue()) // "Lisa"
console.log(cinemaQueue.size()) // "1"
```## Methods
- `enqueue(object: any): void` Adds an object to the queue
- `size(): number` Returns the size of the queue
- `peek(): any` Return most recently added element
- `dequeue(): any` Return most recently added element and delete it from the queue## Runtime complexity
- `enqueue`: O(1)
- `size`: O(1)
- `dequeue`: O(1)
- `peek`: O(1)