Skip to content

feat(data-structures/unstable): align IndexedHeap with heap APIs#7124

Open
tomas-zijdemans wants to merge 2 commits into
denoland:mainfrom
tomas-zijdemans:indexed-heap-next
Open

feat(data-structures/unstable): align IndexedHeap with heap APIs#7124
tomas-zijdemans wants to merge 2 commits into
denoland:mainfrom
tomas-zijdemans:indexed-heap-next

Conversation

@tomas-zijdemans
Copy link
Copy Markdown
Contributor

  • Rework unstable IndexedHeap around set() upsert semantics, replacing update() and pushOrUpdate().
  • Add constructor loading and compare support, aligning IndexedHeap.from() behavior with other heap APIs.
  • Generalize priorities beyond number, enabling max-heaps, bigint, and tuple priorities for stable tie-breaking.
  • Expand docs and tests around the grouped unstable API changes.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.62%. Comparing base (a496da2) to head (d82df6e).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tomas-zijdemans tomas-zijdemans changed the title feat(data-structures/unstable): align IndexedHeap with heap APIs feat(data-structures/unstable): align IndexedHeap with heap APIs May 4, 2026
Copy link
Copy Markdown

@fibibot fibibot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@fibibot
Copy link
Copy Markdown

fibibot commented May 14, 2026

@bartlomieju this is ready to merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants