Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

double-ended-queue

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

double-ended-queue

Extremely fast double-ended queue implementation

  • 2.1.0-0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
504K
decreased by-1.91%
Maintainers
1
Weekly downloads
 
Created

What is double-ended-queue?

The double-ended-queue npm package provides a highly optimized implementation of a double-ended queue (deque), which allows for efficient addition and removal of elements from both ends of the queue. This data structure is useful for various applications such as task scheduling, caching, and more.

What are double-ended-queue's main functionalities?

Add elements to the front

This feature allows you to add elements to the front of the deque. The `unshift` method is used to add elements to the front.

const Deque = require('double-ended-queue');
const deque = new Deque();
deque.unshift(1);
deque.unshift(2);
console.log(deque.toArray()); // Output: [2, 1]

Add elements to the back

This feature allows you to add elements to the back of the deque. The `push` method is used to add elements to the back.

const Deque = require('double-ended-queue');
const deque = new Deque();
deque.push(1);
deque.push(2);
console.log(deque.toArray()); // Output: [1, 2]

Remove elements from the front

This feature allows you to remove elements from the front of the deque. The `shift` method is used to remove elements from the front.

const Deque = require('double-ended-queue');
const deque = new Deque();
deque.push(1);
deque.push(2);
console.log(deque.shift()); // Output: 1
console.log(deque.toArray()); // Output: [2]

Remove elements from the back

This feature allows you to remove elements from the back of the deque. The `pop` method is used to remove elements from the back.

const Deque = require('double-ended-queue');
const deque = new Deque();
deque.push(1);
deque.push(2);
console.log(deque.pop()); // Output: 2
console.log(deque.toArray()); // Output: [1]

Access elements by index

This feature allows you to access elements by their index in the deque. The `get` method is used to retrieve elements by index.

const Deque = require('double-ended-queue');
const deque = new Deque();
deque.push(1);
deque.push(2);
console.log(deque.get(0)); // Output: 1
console.log(deque.get(1)); // Output: 2

Other packages similar to double-ended-queue

Keywords

FAQs

Package last updated on 05 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc