Skip to content
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

Inconsistency in *_mut functions #62

Open
msrd0 opened this issue Feb 25, 2025 · 0 comments
Open

Inconsistency in *_mut functions #62

msrd0 opened this issue Feb 25, 2025 · 0 comments

Comments

@msrd0
Copy link

msrd0 commented Feb 25, 2025

Right now, PriorityQueue::get_mut does not allow modifying the item of the queue (which is in line with the API of other maps in the rust ecosystem) but PriorityQueue::iter_mut does which is both inconsistent with the get_mut function and inconsistent with the API of other maps in the rust ecosystem.

I propose to add PriorityQueue::get_mut2 or PriorityQueue::get_full_mut2 and PriorityQueue::iter_mut2 similar to how the underlying IndexMap works and mark PriorityQueue::iter_mut as deprecated. Then, in the next major version, I propose to replace iter_mut with an iterator that does not allow modifying the item but just the priority.

The same is true for the DoublePriorityQueue.

If you agree to this change, I can send a PR if you want.

Btw for the motivation: My items have a "parent" that is not part of the eq/hash implementation but needs to be updated when changing the priority of the item as well, so I need the get_mut2 functionality. The alternative would be interior mutability which I'd rather not use, or iterating through the entire q to change one single element, which I'd also rather not do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant