New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

heapq-ts

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

heapq-ts

Library for using heap-queue with ts

  • 1.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

heapq-ts

Library for using heap-queue with ts

install
npm i heapq-ts
import
import Heap_Queue from "heapq-ts";

examples

maxheap
const heapq: Heap_Queue = new Heap_Queue();
heapq.push(4);
heapq.push(1);
heapq.push(2);
console.log(heapq.top()); // 4
minheap
const heapq: Heap_Queue = new Heap_Queue(true);
heapq.push(4);
heapq.push(1);
heapq.push(2);
console.log(heapq.top()); // 1
custom comparison
  interface Person {
    height:number;
    weight:number;
    grade:number;
  }

  const p1 = {
    height: 3222,
    weight: 22,
    grade: 1
  }

  const p2 = {
    height: 3222,
    weight: 22,
    grade: 9
  }

  const p3 = {
    height: 88,
    weight: 4532,
    grade: 1
  }

  const p4 = {
    height: 88,
    weight: 184,
    grade: 2
  }

  const heapq: Heap_Queue = new Heap_Queue<Person>((p1, p2) => {
    if (p1.height === p2.height) {
      if (p1.weight === p2.weight) {
        return p1.grade - p2.grade;
      }
      return p2.weight - p1.weight;
    }
    return p2.height - p1.height;
  });

  heapq.push(p1);
  heapq.push(p2);
  heapq.push(p3);
  heapq.push(p4);

  console.log(heapq.top());  //   { height: 3222, weight: 22, grade: 1 }
  heapq.pop();
  console.log(heapq.top());  //   { height: 3222, weight: 22, grade: 9 }

method

push(item)

push item in the heap

pop()

pop the smallest item or largest item of the heap and return

top()

get the smallest item or largest item

size()

get the length of heap

empty()

check if the length is empty or not

Keywords

FAQs

Package last updated on 14 Jun 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

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