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

add .duplicates() and .duplicates_by(..) operations #502

Merged
merged 1 commit into from Jan 21, 2021

Conversation

petrosagg
Copy link
Contributor

Uses a HashMap to detect duplicates in an iterator and emits them only once. The implemention is similar to the unique() and unique_by() methods but in this case the items are never cloned.

src/duplicate_impl.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@petrosagg
Copy link
Contributor Author

@jswrenn thanks for taking another look. I just rebased on top of master and I'm happy to resolve the naming as you see fit :)

@petrosagg
Copy link
Contributor Author

@jswrenn should be good to merge now :)

@petrosagg petrosagg changed the title add .duplicate() and .duplicate_by(..) operations add .duplicateσ() and .duplicateσ_by(..) operations Jan 18, 2021
@petrosagg petrosagg changed the title add .duplicateσ() and .duplicateσ_by(..) operations add .duplicates() and .duplicates_by(..) operations Jan 18, 2021
src/duplicates_impl.rs Outdated Show resolved Hide resolved
@petrosagg petrosagg force-pushed the duplicate-iter branch 2 times, most recently from 30f749d to 5a620b8 Compare January 20, 2021 12:59
Copy link
Member

@jswrenn jswrenn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kudos for unifying the implementations! I just have one last edit for you. :-)

src/duplicates_impl.rs Outdated Show resolved Hide resolved
Uses a HashMap to detect duplicates in an iterator and emits them only
once. Items are never cloned.

Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
@jswrenn jswrenn added this to the next milestone Jan 21, 2021
Copy link
Member

@jswrenn jswrenn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! This PR turned into a really excellent case-study in unifying similar implementations and using internal iteration, that I think will be really informative elsewhere in itertools.

bors r+

@bors bors bot merged commit 853f064 into rust-itertools:master Jan 21, 2021
@bors
Copy link
Contributor

bors bot commented Jan 21, 2021

Build succeeded:

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

Successfully merging this pull request may close these issues.

None yet

3 participants