https://github.com/andrewnester/ts-heapq
Heap queue algorithm implementation for Typescript based on heapq.py module from CPython
https://github.com/andrewnester/ts-heapq
heap heap-queue heapq heapsort priority-queue python ts typescript
Last synced: 27 days ago
JSON representation
Heap queue algorithm implementation for Typescript based on heapq.py module from CPython
- Host: GitHub
- URL: https://github.com/andrewnester/ts-heapq
- Owner: andrewnester
- Created: 2018-06-16T11:38:13.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2025-02-19T17:40:15.000Z (about 1 year ago)
- Last Synced: 2025-07-07T07:18:53.504Z (9 months ago)
- Topics: heap, heap-queue, heapq, heapsort, priority-queue, python, ts, typescript
- Language: TypeScript
- Size: 82 KB
- Stars: 2
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Heapq for Typescript
[](https://github.com/ellerbrock/typescript-badges/)
[](https://github.com/andrewnester/ts-heapq/actions/workflows/build.yml)
[](https://codeclimate.com/github/andrewnester/ts-heapq/maintainability)
[](https://badge.fury.io/js/ts-heapq)
[](https://nodei.co/npm/ts-heapq/)
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 = new Heapq();
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 = new Heapq([], 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;