d-ary-heap 2.5.0 โ 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -29
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|

|
|
2
2
|

|
|
3
3
|
|
|
4
|
-
# d-Heap Priority Queue (TypeScript) v2.
|
|
4
|
+
# d-Heap Priority Queue (TypeScript) v2.6.0
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
**Wikipedia-standard d-ary heap** with configurable arity, O(1) item lookup, and zero-cost comparison-count instrumentation. Cross-language API parity with C++, Go, Rust, and Zig.
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
## ๐ฌ See it in action
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
**[Interactive demo โ](https://pcfvw.github.io/d-Heap-priority-queue/)**
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
- **
|
|
19
|
-
- **
|
|
20
|
-
- **
|
|
21
|
-
- **
|
|
12
|
+
Watch the heap tree update as items are inserted, popped, and re-prioritized. Toggle arity (d=2 / d=4 / d=8) to see how tree depth changes. Step through Dijkstra's algorithm on a weighted graph, or run **race mode** to compare all three arities side-by-side. Built with React Flow; runs in the browser, no install.
|
|
13
|
+
|
|
14
|
+
## Why this crate?
|
|
15
|
+
|
|
16
|
+
If you already know you want a priority queue, here's what `d-ary-heap` gives you over `js-priority-queue`, `priority-queue`, and other npm alternatives:
|
|
17
|
+
|
|
18
|
+
- **Configurable arity `d`** (not just d=2). Pick `d=4` for cache-friendlier inserts, `d=8` for very insert-heavy workloads.
|
|
19
|
+
- **O(1) item lookup + priority updates.** `increasePriority(item)`, `decreasePriority(item)`, `updatePriority(item)` โ the operations Dijkstra and A\* actually need. Most npm priority-queue packages don't expose these.
|
|
20
|
+
- **Zero-cost comparison-count instrumentation** (in the library since v2.4.0; cross-language identical since v2.6.0). Opt-in `instrumentComparator(...)` + `onBeforeOperation` / `onAfterOperation` heap hooks; JIT-elided when not in use. See [Instrumentation](#instrumentation-v240) below.
|
|
21
|
+
- **Cross-language API parity** with Rust, Go, C++, and Zig โ same method names, same complexity guarantees, **byte-for-byte identical comparison counts** on shared benchmarks (verified across 24 cells ร 5 languages).
|
|
22
|
+
- **Zero runtime dependencies. Full TypeScript types.**
|
|
23
|
+
- **Published numbers**: see [`benchmarks/`](https://github.com/PCfVW/d-Heap-priority-queue/tree/master/benchmarks) for cross-language Dijkstra benchmarks (24 cells ร 5 languages) and the [methodology](https://github.com/PCfVW/d-Heap-priority-queue/blob/master/benchmarks/methodology.md).
|
|
22
24
|
|
|
23
25
|
## Installation
|
|
24
26
|
|
|
@@ -232,15 +234,15 @@ For a d-ary heap with n elements:
|
|
|
232
234
|
|
|
233
235
|
### Cross-Language Consistency
|
|
234
236
|
|
|
235
|
-
|
|
237
|
+
Instrumentation is implemented in **all five languages** with **byte-for-byte identical comparison counts** (verified across 24 (graph, arity) cells; see [benchmarks/README.md](https://github.com/PCfVW/d-Heap-priority-queue/blob/master/benchmarks/README.md)). Each language uses its idiomatic zero-cost mechanism:
|
|
236
238
|
|
|
237
|
-
| Language | Mechanism
|
|
238
|
-
|
|
239
|
-
| TypeScript | Optional hooks + instrumented comparator
|
|
240
|
-
| Go | Nil stats pointer
|
|
241
|
-
| Rust | Generic over StatsCollector trait
|
|
242
|
-
| C++ | Template policy class
|
|
243
|
-
| Zig | Comptime bool parameter
|
|
239
|
+
| Language | Mechanism | Overhead When Disabled |
|
|
240
|
+
|------------|-------------------------------------------------|------------------------|
|
|
241
|
+
| TypeScript | Optional hooks + instrumented comparator | Zero (JIT optimization) |
|
|
242
|
+
| Go | Nil stats pointer | ~1 cycle (nil check) |
|
|
243
|
+
| Rust | Generic over `StatsCollector` trait | Zero (monomorphization + ZST layout) |
|
|
244
|
+
| C++ | Template policy class + `[[no_unique_address]]` | Zero (inlining + ZST collapse) |
|
|
245
|
+
| Zig | Comptime bool parameter on `DHeapWithStats` | Zero (branch elimination + `void` field type) |
|
|
244
246
|
|
|
245
247
|
## Priority Update Semantics
|
|
246
248
|
|
|
@@ -261,14 +263,9 @@ This library uses **importance-based** semantics:
|
|
|
261
263
|
|
|
262
264
|
## Performance
|
|
263
265
|
|
|
264
|
-
###
|
|
266
|
+
### Benchmarks
|
|
265
267
|
|
|
266
|
-
|
|
267
|
-
|-----------|-----|-----|-----|
|
|
268
|
-
| 100k inserts | ~21ms | ~13ms | ~11ms |
|
|
269
|
-
| 100k pops | ~187ms | ~136ms | ~140ms |
|
|
270
|
-
| Throughput (insert) | ~2.2M ops/sec | | |
|
|
271
|
-
| Throughput (pop+insert) | ~900k ops/sec | | |
|
|
268
|
+
See [`benchmarks/`](https://github.com/PCfVW/d-Heap-priority-queue/tree/master/benchmarks) for the Phase 3 cross-language Dijkstra sweep (24 cells ร 5 languages, K=2 warmup + 10 timed reps each, median + IQR reporting). On AMD Ryzen 9 5950X with Node v24.11.1, the TypeScript example runs `huge_dense ร d=8` (75 936 heap comparisons) at a median of **13.4 ms (~177 ns/cmp)** โ within 25% of Go's 11.0 ms / 145 ns/cmp on the same workload. The full methodology is in [`benchmarks/methodology.md`](https://github.com/PCfVW/d-Heap-priority-queue/blob/master/benchmarks/methodology.md).
|
|
272
269
|
|
|
273
270
|
### Performance Tips
|
|
274
271
|
|
|
@@ -324,3 +321,7 @@ npm run typecheck
|
|
|
324
321
|
## Reference
|
|
325
322
|
|
|
326
323
|
Section A.3, [d-Heaps](https://en.wikipedia.org/wiki/D-ary_heap), pp. 773โ778 of Ravindra Ahuja, Thomas Magnanti & James Orlin, **Network Flows** (Prentice Hall, 1993).
|
|
324
|
+
|
|
325
|
+
## License
|
|
326
|
+
|
|
327
|
+
Apache License 2.0 โ See [LICENSE](https://github.com/PCfVW/d-Heap-priority-queue/blob/master/LICENSE) for details.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "d-ary-heap",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.6.0",
|
|
5
5
|
"description": "High-performance d-ary heap priority queue with O(1) item lookup, configurable arity, and min/max heap support",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|