Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

denque

invertase43mApache-2.02.1.0TypeScript support: included

The fastest javascript implementation of a double-ended queue. Used by the official Redis, MongoDB, MariaDB & MySQL libraries for Node.js and many other libraries. Maintains compatability with deque.

data-structure, data-structures, queue, double, end, ended, deque, denque, double-ended-queue

readme

Denque

NPM downloads NPM version Tests status Coverage License Follow on Twitter

Denque is a well tested, extremely fast and lightweight double-ended queue implementation with zero dependencies and includes TypeScript types.

Double-ended queues can also be used as a:

This implementation is currently the fastest available, even faster than double-ended-queue, see the benchmarks.

Every queue operation is done at a constant O(1) - including random access from .peekAt(index).

Works on all node versions >= v0.10

Quick Start

Install the package:

npm install denque

Create and consume a queue:

const Denque = require("denque");

const denque = new Denque([1,2,3,4]);
denque.shift(); // 1
denque.pop(); // 4

See the API reference documentation for more examples.


Who's using it?

... and many more.


License


Built and maintained by Invertase.

changelog

2.1.0

  • fix: issue where clear() is still keeping references to the elements (#47)
  • refactor: performance optimizations for growth and array copy (#43)
  • refactor: performance optimizations for toArray and fromArray (#46)
  • test: add additional benchmarks for queue growth and toArray (#45)

2.0.1

  • fix(types): incorrect return type on size()

2.0.0

  • fix!: push & unshift now accept undefined values to match behaviour of Array (fixes #25) (#35)
    • This is only a BREAKING change if you are currently expecting push(undefined) and unshift(undefined) to do nothing - the new behaviour now correctly adds undefined values to the queue.
    • Note: behaviour of push() & unshift() (no arguments) remains unchanged (nothing gets added to the queue).
    • Note: If you need to differentiate between undefined values in the queue and the return value of pop() then check the queue .length before popping.
  • fix: incorrect methods in types definition file

1.5.1

  • perf: minor performance tweak when growing queue size (#29)

1.5.0

  • feat: adds capacity option for circular buffers (#27)