-
Notifications
You must be signed in to change notification settings - Fork 168
Add move_index to change the position of an entry #176
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
Conversation
I'm not entirely committed to the name |
c4c03e6
to
94cb62a
Compare
I just noticed that #83 had a similar method called |
I would love to get access to this function. Still thinking about merging it in? |
Sure -- do you have any thoughts about the name? |
I think Reads really nicely as move index from x to y Or |
This moves the position of a key-value pair from one index to another by shifting all other pairs in-between, making this an O(n) operation. This could be used as a building-block for other operations, like indexmap-rs#173 which wants to insert at a particular index. You can `insert_full` to insert it _somewhere_, then choose whether to `move_index` depending on whether you want to also change pre-existing entries.
Ignore my last comment if you saw it (now deleted). This works great, I tired it out on my fork. This is exactly what I needed to make IndexSet and IndexMap work with my data structure. |
This moves the position of a key-value pair from one index to another by
shifting all other pairs in-between, making this an O(n) operation.
This could be used as a building-block for other operations, like #173
which wants to insert at a particular index. You can
insert_full
toinsert it somewhere, then choose whether to
move_index
depending onwhether you want to also change pre-existing entries.