priorityQueue

DataTable
stable

Create a min-heap priority queue for generic items. Elements are inserted in priority order (lower number = higher priority) and the queue exposes enqueue, size, count, and dequeue operations.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

arr
T[]
[]
Optional seed array of elements. Each element is inserted with priority 0.

API

Return value

The value returned by this util.

An object with four methods: enqueue (insert with priority), size (total count), count (count of elements sharing the lowest-priority bucket), and dequeue (remove and return the next element).

Usage

Examples

Ready-to-paste usage snippets.

Sort items by priority

typescript