-
Notifications
You must be signed in to change notification settings - Fork 9
feat: Add PriorityQueue #392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rvanasa
reviewed
Sep 15, 2025
Collaborator
rvanasa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR! Added a few comments.
rvanasa
approved these changes
Sep 17, 2025
Collaborator
|
Should be ready to merge after updating the |
3a539f2 to
665c8c4
Compare
rvanasa
reviewed
Sep 26, 2025
96c3a19 to
664d092
Compare
Set wrapper implementations
P4P5T123
pushed a commit
that referenced
this pull request
Oct 9, 2025
* Partial implementation. * Fix bug and add peek. * Started with tests, and more functions. * Towards more tests, adding SetPriorityQueue. * Completing first implementation, with tests. * Add comments to PriorityQueue.mo * Move set implementation and add benchmark. * Better holes. * Extra benchmark. * More tests. * . * Comments. * Optimization. * Comments for SetWrapper. * Move SetWrapper. * Run format. * . * npm run validate * Fix imports in docstrings. * Add Changelog entry. * Fix Changelog entry. * Remove inefficient push and pop operations (and benchmarks for them). * Move PriorityQueueSet.mo * Fix validation. * Update Changelog.
christoph-dfinity
added a commit
that referenced
this pull request
Oct 13, 2025
* chore: updates matchers package to mops release (#394) * makes comparison arguments to Map functions implicit * use implicits in tests for Map * make comparison arguments to Set functions implicit * update Set tests to use implicits * remove local bindings, now that we can disambiguate Nat and Int * make equal arguments implicit * rename internal Map and Set size to size_ to avoid clash with contextual dot * Implicit pattern across entire `core` package (#398) * First pass * Another pass * Fix stragglers * Fix more stragglers * Apply suggestions from code review Co-authored-by: Christoph <christoph.hegemann@dfinity.org> Co-authored-by: Claudio Russo <claudio@dfinity.org> * Apply suggestions from code review Co-authored-by: Claudio Russo <claudio@dfinity.org> * Various fixes * Apply suggestions from code review Co-authored-by: Claudio Russo <claudio@dfinity.org> * Fix * Update API lockfile --------- Co-authored-by: Christoph <christoph.hegemann@dfinity.org> Co-authored-by: Claudio Russo <claudio@dfinity.org> * rename .size on Queue * add TODO comment * I was using a stale compiler * updates the toolchain to a pre-release * updated mops to pull down draft branch and adjust tests (#399) * feat: Add PriorityQueue (#392) * Partial implementation. * Fix bug and add peek. * Started with tests, and more functions. * Towards more tests, adding SetPriorityQueue. * Completing first implementation, with tests. * Add comments to PriorityQueue.mo * Move set implementation and add benchmark. * Better holes. * Extra benchmark. * More tests. * . * Comments. * Optimization. * Comments for SetWrapper. * Move SetWrapper. * Run format. * . * npm run validate * Fix imports in docstrings. * Add Changelog entry. * Fix Changelog entry. * Remove inefficient push and pop operations (and benchmarks for them). * Move PriorityQueueSet.mo * Fix validation. * Update Changelog. * Update implicits for RealTimeQueue * Update implicits for PriorityQueue * Update API lockfile --------- Co-authored-by: Ryan Vandersmith <ryan.vandersmith@dfinity.org> Co-authored-by: Claudio Russo <claudio@dfinity.org> Co-authored-by: Andrei Constantinescu <andrei.constantinescu@dfinity.org>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds PriorityQueue support to the core library, implementing two variants:
List(undersrc/PriorityQueue.mo).Set(underbench/utils/PriorityQueueSet.moand intended for benchmarking/testing purposes only).Resolves #391.
Tests
The PR contains comprehensive unit tests, including cross-testing the two implementations against each other to ensure correctness, as well as more complex test scenarios such as long randomized sequences of operations and exhaustive testing of all possible small sequences to catch edge cases.
Benchmarks
The PR contains extensive benchmarks comparing the performance of both implementations (on
Natvalues). See table below.Note: an earlier commit in this PR considered simpler but less efficient ways of implementing
pushandpopfor the heap-based implementation. These were removed in favor of more efficient implementations based on the gap technique to avoid needless copies. Concretely, commit 664d092 distinguished between:push(removed) andpushBetter(now renamedpush).pop(removed) andpopBetter(now renamedpop).The table below is for the state of the code at this commit.
Instructions
Heap (@alexandru-uta noted that these seem broken at the moment, likely due to independent reasons):
Garbage Collection