-
Notifications
You must be signed in to change notification settings - Fork 169
Additional operations for manipulating iteration order #83
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
Additional operations for manipulating iteration order #83
Conversation
Is there anything preventing this from being merged? I've updated the changes below.
|
It makes sense to me!
The hashbrown PR will have priority for now, I fear this PR needs to be rebased again after that is merged. |
Thanks for the feedback. I am currently struggling with mental health issues that might make it difficult for me to work on this for a while; otherwise I would make the suggested changes myself. If someone else wants to fix the issues so the feature (or something similar) can potentially be merged, feel free. |
I have a very similar use case. I would much rather contribute to this pull request than roll my own datastructure from scratch. If the changes were made and branch merged, how soon might this make it into a public release? (I'd prefer not to use a |
Once it's merged, we can publish a release at any time. |
We now have |
This PR adds operations to
IndexMap
(andIndexSet
) that allow an entry to be moved to a specific position in the iteration order, while preserving the order of all other entries. The operation's average computation time is proportional to the distance between the entry's current position and the new position, assuming that probing the hash table takes constant time on average.The PR requires an upgrade to Rust version 1.26, because it relies on the
rotate_left
androtate_right
methods of the slice type. If upgrading to 1.26 is deemed inappropriate at this time, it may be necessary to delay merging this PR.The new operations also may allow for an alternative implementation of
ordered_remove
(from PR #15), in which the element being removed is first moved to the end of the ordering, thenIndexMap::pop()
is called. This might be more efficient if the element to be removed is already close to the end. I haven't included that idea in the PR, but it could be considered if the PR is accepted.Please let me know if you find any problems in the PR that I need to fix. One thing I am unsure about is whether returning
Option<()>
is or is not an appropriate/idiomatic way of supporting error detection in a method that wouldn't normally return anything.Use Case
My use case for this PR is that I am planning to create a GUI application where the user can manage a list of items, including reordering the items by dragging and dropping an item in the list. Internally, the items may reference each other by a unique key. Ideally, I want to be able to look up an item efficiently by both its numerical index and its unique key. IndexMap seems like a good fit for this use case, and this PR would make it easier for me to implement the reordering through drag and drop.