New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@kartjim/priority-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

@kartjim/priority-queue

Priority queue implementation in JavaScript

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

priority-queue npm version Node.js CI

Priority queue(优先队列) implementation in JavaScript

install

npm i @kartjim/priority-queue

import

import PriorityQueue from '@kartjim/priority-queue';

or use CDN:

<script src="https://cdn.jsdelivr.net/npm/@kartjim/priority-queue@1.0.2/priorityqueue.min.js"></script>

use

const data = [];
for (let i = 0; i < 50; i++) {
    data.push(~~(50 * Math.random()));
}

const sorted = data.slice().sort((a, b) => a - b);

const heap = new PriorityQueue();
for (let i = 0; i < data.length; i++) {
    heap.push(data[i]);
}

heap.peek() === sorted[0] // true

let ans = [];
while (!heap.isEmpty()) {
    ans.push(heap.pop());
}

ans == sorted // deeply equal

API

  • constructor
    • constructor(data?: T[],compare?: (a: T, b: T) => number);
  • push(val: T) : void;
    • push an element into PriorityQueue
  • peek() : T | undefined;
    • get the top element
  • pop() : T | undefined;
    • pop an element, and return it
  • isEmpty() : boolean;
    • check if the PriorityQueue is empty

Keywords

priority-queue

FAQs

Package last updated on 14 Feb 2023

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