JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 22675
  • Score
    100M100P100Q151039F
  • License MIT

queue implementation in javascript

Package Exports

  • @datastructures-js/queue

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@datastructures-js/queue) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@datastructures-js/queue

build:? npm npm npm

A performant queue implementation in javascript.

Table of Contents

Install

npm install --save @datastructures-js/queue

API

require

const Queue = require('@datastructures-js/queue');

import

import Queue from '@datastructures-js/queue';

create a queue

const queue = new Queue();

.enqueue(element)

adds an element at the back of the queue.

runtime params
O(1) element: {object}
queue.enqueue(10);
queue.enqueue(20);

.front()

peeks on the front element of the queue.

runtime return
O(1) {object}
console.log(queue.front()); // 10

.back()

peeks on the back element in the queue.

runtime return
O(1) {object}
console.log(queue.back()); // 20

.dequeue()

dequeue the front element in the queue. It does not use .shift() to dequeue an element. Instead, it uses an offset the get the front element and only remove elements when reaching half size of the queue.

runtime return
O(1) / O(n/2^k) {object}

Dequeuing all elements takes O(n*log(n)) instead of O(n^2) if using shift().

console.log(queue.dequeue()); // 10
console.log(queue.front()); // 20

.isEmpty()

checks if the queue is empty.

runtime return
O(1) {boolean}
console.log(queue.isEmpty()); // false

.size()

returns the number of elements in the queue.

runtime return
O(1) {number}
console.log(queue.size()); // 1

.toArray()

returns the remaining elements as an array.

runtime return
O(1) {array}
queue.enqueue(4);
queue.enqueue(2);
console.log(queue.toArray()); // [20, 4, 2]

.clear()

clears all elements from the queue.

runtime
O(1)
queue.clear();
queue.size(); // 0

Build

lint + tests

grunt build

License

The MIT License. Full License is here