Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gobengo/heap
Heap data structure written in TypeScript/Deno
https://github.com/gobengo/heap
Last synced: 25 days ago
JSON representation
Heap data structure written in TypeScript/Deno
- Host: GitHub
- URL: https://github.com/gobengo/heap
- Owner: gobengo
- Created: 2020-05-12T00:21:20.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-21T18:18:18.000Z (almost 4 years ago)
- Last Synced: 2024-10-03T15:29:06.745Z (about 1 month ago)
- Language: TypeScript
- Size: 4.88 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @gobengo/heap
A Min/Max Heap in TypeScript.
i.e. a collection of sorted values that requires O(n) space and supports the following operations:
* buildHeap - Create Heap from initialValues in O(n) time
* length - get number of items in collection in O(1) time
* peek - get first item in collection in O(1) time
* pop - remove the first item in collection in O(log(n)) time
* push - add a new item to the collection in O(log(n)) timeConsider using it for algorithms that benefit from a a [Priority Queue](https://en.wikipedia.org/wiki/Priority_queue), e.g. [Djikstra's Algorithm for finding the shortest paths between nodes in a graph](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm).
It should work with [deno](https://deno.land/).
## Run Tests
`deno test heap.test.ts`
## Build
The following command will write an ES Module to stdout that you can use in many places (e.g. the browser, Node 14)
`deno bundle heap.ts`
Example:
```
deno bundle heap.ts > heap.mjsnode -e "(async () => { console.log(await import('./heap.mjs')) })()"
# [Module] {
# Heap: [Function: Heap],
# MaxHeap: [Function: MaxHeap],
# MinHeap: [Function: MinHeap]
# }```