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
HeapPriorityQueue doesn't let one iterate in unsorted order #140
Comments
Adding a member to an implementation class is not a breaking change, so we can add it to It's somewhat annoying to add an operation which is not general to all If we do support it anyway, I'd suggest |
I've added |
The The
In my case, I have very big priority lists with many millions of entries, and doing operations to consider all the elements (in no particular order) is very expensive (and I try to do it as little as possible). The big up front allocation can create a big delay where I can't use async boundaries to let other code paths remain responsive. Being able to iterate the backing data structure with no duplication makes this operation cheaper. Make no mistake, |
So a better API would be I'll think about this again, we haven't released it yet. |
I missed this comment before I published. It's released, but with a prerelease Do we need to consider quickly reverting that to avoid it getting picked up by flutter? cc @jakemac53 |
Won't be needed. If we need something different, we can add it that and keep I am not particularly happy about adding a way to iterate elements in-place. The But OK, let's try and see how big an impact an |
No, I do not need a destructive iterator. That means I need to pay I just want to non-destructively iterate the elements in the queue in no particular order in linear time with constant memory use. |
Have now landed |
My code has several huge priority queues using
HeapPriorityQueue
, where it occasionally needs to consider all the elements in the queue where the order doesn't matter (e.g. to tally up how long it will take to process the queue, or to consider all the items and move a few to another queue if circumstances changes).However,
HeapPriorityQueue
only offerstoList()
andtoSet()
for this purpose. However, they spend O(nlogn) to sort the queue (and I need a linear time algorithm) and duplicates the data structure (I just need constant memory). The only way to iterate the queue in linear time in unsorted order is to useremoveAll()
, however it is destructive.The
HeapPriorityQueue
internally just uses a list to manage the data structure, which is what is returned byremoveAll()
. It could easily gain aIterable<E> get unsorted
getter or something that returns the backing data structure with the appropriate concurrent modification protections.This is probably a breaking change and needs a major version bump in case anyone implemented
HeapPriorityQueue
.I'm currently working around the issue associating each priority queue with a
Set
in my mod, however it duplicates the amount of memory spent on the queues.The text was updated successfully, but these errors were encountered: