You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@datastructures-js/priority-queue

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@datastructures-js/priority-queue

a performant priority queue implementation using a Heap data structure.

5.4.0
Source
npmnpm
Version published
Weekly downloads
208K
33.52%
Maintainers
1
Weekly downloads
 
Created

What is @datastructures-js/priority-queue?

@datastructures-js/priority-queue is an npm package that provides a robust implementation of a priority queue data structure. It allows you to manage a collection of elements where each element is associated with a priority, and elements are served based on their priority.

What are @datastructures-js/priority-queue's main functionalities?

Creating a Priority Queue

This code demonstrates how to create a new instance of a MinPriorityQueue using the @datastructures-js/priority-queue package.

const { MinPriorityQueue } = require('@datastructures-js/priority-queue');
const pq = new MinPriorityQueue();

Adding Elements

This code shows how to add elements to the priority queue with associated priorities.

pq.enqueue('task1', 1);
pq.enqueue('task2', 2);

Removing Elements

This code demonstrates how to remove and return the element with the highest priority from the priority queue.

const highestPriorityElement = pq.dequeue();

Peeking at the Highest Priority Element

This code shows how to peek at the element with the highest priority without removing it from the queue.

const highestPriorityElement = pq.front();

Checking if the Queue is Empty

This code demonstrates how to check if the priority queue is empty.

const isEmpty = pq.isEmpty();

Other packages similar to @datastructures-js/priority-queue

Keywords

queue

FAQs

Package last updated on 08 Jan 2024

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