Change remove from swap to shift in index map#9049
Merged
alamb merged 2 commits intoapache:mainfrom Jan 29, 2024
synnada-ai:minor/change_swap_to_shift
Merged
Change remove from swap to shift in index map#9049alamb merged 2 commits intoapache:mainfrom synnada-ai:minor/change_swap_to_shift
alamb merged 2 commits intoapache:mainfrom
synnada-ai:minor/change_swap_to_shift
Conversation
6 tasks
alamb
approved these changes
Jan 29, 2024
Contributor
alamb
left a comment
There was a problem hiding this comment.
Thank you @mustafasrepo -- this makes sense to me
I also double checked the indexmap docs and maintaing the order of the removed item makes sense to me
https://docs.rs/indexmap/latest/indexmap/map/struct.IndexMap.html#method.swap_remove
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
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.
Which issue does this PR close?
Closes #.
Rationale for this change
In the #PR9034, @viirya resolved CI error, by replacing
.removemethod ofIndexMapwith.swap_remove(they are equal).However, while reviewing I thought maybe it is better to use
.shift_remove(where relative order is preserved after removal).As an example, assume we have the alternative valid orderings:
[d ASC, b ASC],[e ASC, f ASC],[d ASC, h ASC],and
find_longest_permutationis called with expressions:d, h, e, f, b. Conceptually any result in the following form:[permutation(d ASC, e DESC) + permutation(b ASC, f ASC, h DESC)]is valid. Meaning,following orderings:
[d ASC, e ASC, b ASC, f ASC, h ASC],[e ASC, d ASC, b ASC, f ASC, h ASC],[d ASC, e ASC, f ASC, b ASC, h ASC],...
are all valid.
However, to not depend on any internal implementation. It is better to prefer argument ordering between permutations. e.g we want to return ordering:
[d ASC, e ASC, b ASC, f ASC, h ASC], for the argumentsd, h, e, f, b.Similarly, we want to return ordering:
[e ASC, d ASC, b ASC, f ASC, h ASC], for the argumentse, d, h, f, bto be consistent, and to be least surprising.Replacing
.swap_removewith.shift_removeensures this property.What changes are included in this PR?
Are these changes tested?
Yes
Are there any user-facing changes?