Current collected state Current
Observed since 20 Oct, 22:05 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
A TypeScript implementation of a min heap data structure
A high-performance TypeScript implementation of a min heap data structure that supports both ESM and CommonJS. This implementation is optimized for handling large datasets and provides stable ordering for elements with equal priorities.
pnpm add @0bipinnata0/heap
import { push, pop, peek } from '@0bipinnata0/heap'
// Create a min heap array for objects with sortIndex
const heap: Array<{id: number, sortIndex: number}> = []
// Push elements
push(heap, { id: 1, sortIndex: 5 })
push(heap, { id: 2, sortIndex: 3 })
push(heap, { id: 3, sortIndex: 7 })
push(heap, { id: 4, sortIndex: 1 })
// Peek at minimum element without removing it
console.log(peek(heap)) // { id: 4, sortIndex: 1 }
// Pop elements in ascending order
console.log(pop(heap)) // { id: 4, sortIndex: 1 }
console.log(pop(heap)) // { id: 2, sortIndex: 3 }
console.log(pop(heap)) // { id: 1, sortIndex: 5 }
console.log(pop(heap)) // { id: 3, sortIndex: 7 }
push(heap: T[], value: T): void
peek(heap: T[]): T | null
pop(heap: T[]): T | null
The package includes comprehensive test coverage for:
Run tests with:
pnpm test
MIT
Download counts and popularity will appear here as the collector receives them.
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 22:05 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:da14539c5e1d81841264fe339cbd19b3cc59a9cc95101b97d52a37f21d9e2731