@4bitlabs/numeric-deque
TypeScript icon, indicating that this package has built-in type declarations

1.1.7 • Public • Published

@4bitlabs/numeric-deque License NPM Version NPM Downloads

A numeric-container backed by a TypedArray ring-buffer. Implements both stack (FILO) and queue (FIFO) methods, a.k.a. a deque.

Installation

Using npm:

$ npm install --save @4bitlabs/numeric-deque

Using yarn:

$ yarn add @4bitlabs/numeric-deque

Using pnpm:

$ pnpm add @4bitlabs/numeric-deque

Documentation

Full documentation for the library can be found here

Basic Usage

import { NumericDeque } from '@4bitlabs/numeric-deque';

// Create a numeric deque to hold *atleast* 10 items.
const deque = new NumericDeque(10);

deque.push(2);
deque.push(3);
deque.push(4);
deque.unshift(1);

while (!deque.isEmpty()) {
  console.log(deque.shift());
}

// Output: 1, 2, 3, 4

Note, the capacity given to the constructor is the minimum required capacity. The actual capacity of the deque may be larger.

Peek

const deque = new NumericDeque(10);

deque.push(1);
deque.push(2);
deque.push(3);
deque.push(4);

console.log(deque.peekHead()); // 1
console.log(deque.peekTail()); // 4

TypedArray backed deques

By the default, the ring-buffer is backed by Float64Array, however, you can any of the numeric TypedArrays for your backing buffer:

import { NumericDeque } from '@4bitlabs/numeric-deque';

const bytes = new NumericDeque(300, Uint8ClampedArray);
const signedData = new NumericDeque(16, Int16Array);
const buffer = new NumericDeque(2_000, Uint32Array);

License

ISC

Package Sidebar

Install

npm i @4bitlabs/numeric-deque

Weekly Downloads

1

Version

1.1.7

License

ISC

Unpacked Size

10.5 kB

Total Files

11

Last publish

Collaborators

  • 32bitkid