feat(data-structures/unstable): align IndexedHeap with heap APIs#7124
feat(data-structures/unstable): align IndexedHeap with heap APIs#7124tomas-zijdemans wants to merge 2 commits into
IndexedHeap with heap APIs#7124Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7124 +/- ##
=======================================
Coverage 94.61% 94.62%
=======================================
Files 634 634
Lines 51801 51824 +23
Branches 9329 9335 +6
=======================================
+ Hits 49011 49036 +25
Misses 2216 2216
+ Partials 574 572 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
IndexedHeap with heap APIs
fibibot
left a comment
There was a problem hiding this comment.
The update/pushOrUpdate collapse into a single set() upsert matches Map's API and is the natural shape for Dijkstra-style relaxation. Generic priority P = number with the compare option keeps the default ergonomic for the common case and unlocks tuple/bigint/descend variants without internal forks.
from(otherHeap) correctly inherits #compare and reuses the source's heap-array order (still valid under the same comparator); the override branch re-heapifies via Floyd's siftDown in O(n). checkPriority narrowing to typeof === "number" && isNaN is right — NaN only exists in number.
Tests cover the new surface well: tuple stable tie-breaking, bigint past MAX_SAFE_INTEGER, set no-op on identical priority, NaN rejection on both absent and present keys, ArrayLike redirected to from().
- nit:
from(otherHeap, { compare: collection.#compare })re-heapifies even when the comparator is identical to the source's. Cheap edge case to skip, but function identity is fragile so probably not worth optimising.
|
@bartlomieju this is ready to merge |
IndexedHeaparoundset()upsert semantics, replacingupdate()andpushOrUpdate().comparesupport, aligningIndexedHeap.from()behavior with other heap APIs.number, enabling max-heaps,bigint, and tuple priorities for stable tie-breaking.