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

ts-heapq

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-heapq

Heap queue algorithm implementation for Typescript based on heapq.py module from CPython

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18
increased by20%
Maintainers
1
Weekly downloads
 
Created
Source

Heapq for Typescript

TypeScript Build Status Maintainability npm version

NPM

Heap queue algorithm implementation for Typescript based on heapq.py module from CPython

Installation

npm install ts-heapq

Use

Test

Simple example
import { Heapq } from "ts-heapq";

let heap: Heapq<number> = new Heapq<number>();
heap.push(3);
heap.push(1);
heap.push(2);

heap.top(); // return 1;
heap.pop(); // return 1, heap contains [2, 3];
heap.top(); // returns 2;
Implementing max heap using custom comparator
import { Heapq } from "ts-heapq";

let maxHeap: Heapq<number> = new Heapq<number>([], comparator: (a: number, b: number) => a > b);
maxHeap.push(1);
maxHeap.push(3);
maxHeap.push(2);

maxHeap.top(); // return 3;
maxHeap.pop(); // return 3, heap contains [2, 1];
maxHeap.top(); // returns 2;

Keywords

FAQs

Package last updated on 04 Oct 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

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