-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Fix uniquify to handle multiple successive duplicates #126889
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
CollectionUtils.uniquify is based on C++ std::unique. However, C++ iterators are not quite the same as Java iterators. In particular, advancing them only allows grabbing the value once. This commit reworks uniquify to be based on list indices instead of iterators. closes elastic#126883
Pinging @elastic/es-core-infra (Team:Core/Infra) |
Hi @rjernst, I've created a changelog YAML for you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -78,6 +78,7 @@ public void testUniquify() { | |||
assertUniquify(List.of(1, 1, 1), Comparator.naturalOrder(), 1); | |||
assertUniquify(List.of(1, 2, 2, 3), Comparator.naturalOrder(), 3); | |||
assertUniquify(List.of(1, 2, 2, 2), Comparator.naturalOrder(), 2); | |||
assertUniquify(List.of(1, 2, 2, 3, 3, 5), Comparator.naturalOrder(), 4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs a stronger test. I was thinking about this:
- Generate random int
s
for the number of unique items in list - Generate
s
unique numbers - For each random generate random number of repeats (1 to 10)
- Put everything in the list
- uniquify the list
- compare resulting list with a list of only unique numbers that we have from 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a random test, see 62cdd9a
@ldematte I reworked this back to using iterators. I remembered that the reason to use iterators is to support linked lists, since doing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
CollectionUtils.uniquify is based on C++ std::unique. However, C++ iterators are not quite the same as Java iterators. In particular, advancing them only allows grabbing the value once. This commit reworks uniquify to be based on list indices instead of iterators. closes elastic#126883
CollectionUtils.uniquify is based on C++ std::unique. However, C++ iterators are not quite the same as Java iterators. In particular, advancing them only allows grabbing the value once. This commit reworks uniquify to be based on list indices instead of iterators. closes elastic#126883
CollectionUtils.uniquify is based on C++ std::unique. However, C++ iterators are not quite the same as Java iterators. In particular, advancing them only allows grabbing the value once. This commit reworks uniquify to be based on list indices instead of iterators. closes elastic#126883
CollectionUtils.uniquify is based on C++ std::unique. However, C++ iterators are not quite the same as Java iterators. In particular, advancing them only allows grabbing the value once. This commit reworks uniquify to be based on list indices instead of iterators. closes elastic#126883
) CollectionUtils.uniquify is based on C++ std::unique. However, C++ iterators are not quite the same as Java iterators. In particular, advancing them only allows grabbing the value once. This commit reworks uniquify to be based on list indices instead of iterators. closes #126883
) CollectionUtils.uniquify is based on C++ std::unique. However, C++ iterators are not quite the same as Java iterators. In particular, advancing them only allows grabbing the value once. This commit reworks uniquify to be based on list indices instead of iterators. closes #126883
) CollectionUtils.uniquify is based on C++ std::unique. However, C++ iterators are not quite the same as Java iterators. In particular, advancing them only allows grabbing the value once. This commit reworks uniquify to be based on list indices instead of iterators. closes #126883 Co-authored-by: Elastic Machine <[email protected]>
) CollectionUtils.uniquify is based on C++ std::unique. However, C++ iterators are not quite the same as Java iterators. In particular, advancing them only allows grabbing the value once. This commit reworks uniquify to be based on list indices instead of iterators. closes #126883 Co-authored-by: Elastic Machine <[email protected]>
CollectionUtils.uniquify is based on C++ std::unique. This commit fixes the implementation to correctly match std::unique, so that successive ranges of duplicates are handled.
closes #126883