Socket
Socket
Sign inDemoInstall

@datastructures-js/priority-queue

Package Overview
Dependencies
0
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @datastructures-js/priority-queue

priority queue implementation in javascript


Version published
Weekly downloads
47K
decreased by-30.48%
Maintainers
1
Install size
9.52 kB
Created
Weekly downloads
 

Readme

Source

Queue

build:? npm npm npm

elements data type: any type.

Usage

const pQueueFn = require('@datastructures-js/priority-queue');
const pQueue = pQueueFn();

API

.enqueue(element, priority)

adds an element with priority (number) to the back of the queue.

pQueue.enqueue('patient 1', 2); // lower priority
pQueue.enqueue('patient 2', 1); // higher priority

.front()

returns the front element in queue.

console.log(pQueue.front()); // patient 1

.back()

returns the back element in the queue.

console.log(pQueue.back()); // patient 3

.dequeue()

dequeues the highest priority element from the queue.

console.log(pQueue.dequeue()); // patient 2
console.log(pQueue.front()); // patient 1

.isEmpty()

checks if the queue is empty.

console.log(pQueue.isEmpty()); // false

.length()

returns the length of the queue.

console.log(pQueue.length()); // 1

.toArray()

converts the queue to an array from highest prority element to lowest

pQueue.enqueue('patient 3', 5);
pQueue.enqueue('patient 4', 1);
console.log(pQueue.toArray()); // ['patient 4', 'patient 1', 'patient 5']

.clear()

clears the queue

pQueue.clear();
console.log(pQueue.length()); // 0

Build

grunt build

License

The MIT License. Full License is here

Keywords

FAQs

Last updated on 01 Jul 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc