@kyleshevlin/heap
v0.2.0
Published
a basic, customizable heap implementation in TypeScript
Readme
heap
Just a basic, customizable heap implementation in TypeScript
Usage
import { Heap, MinHeap, MaxHeap } from '@kyleshevlin/heap'
const min = new MinHeap()
const max = new MinHeap()
type Task = {
priority: number
}
const custom = new Heap<Task>((a, b) => a.priority < b.priority)API
constructor<T>(comparator: (a: T, b: T) => boolean)clearinsert(value: T)insertMany(values: T[])extractpeeksize
Tips
For min-heaps, your comparator should return true when a < b, and vice versa for max heaps.
