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

Dedup functionality #2

Closed
iopq opened this issue Apr 18, 2015 · 8 comments
Closed

Dedup functionality #2

iopq opened this issue Apr 18, 2015 · 8 comments
Labels

Comments

@iopq
Copy link

@iopq iopq commented Apr 18, 2015

I'd like to .sort() and .dedup() the SmallVecs so I can see which values are unique. Failing that, I guess SmallHashSet would work too.

@iopq
Copy link
Author

@iopq iopq commented Apr 19, 2015

I don't actually know if it would be faster to do .sort(). and .dedup() or to do a .contains() in a loop...

@SimonSapin
Copy link
Member

@SimonSapin SimonSapin commented Apr 19, 2015

.sort() should Just Work, through DerefMut to [T]. You may also want to try quicksort instead: https://github.com/servo/rust-quicksort it is not a stable sort (which doesn’t matter if you dedup) but it doesn’t allocate.

Vec::dedup can not be used directly, but I think its code can be copied mostly unchanged. It’d just need .truncate(n) to be added. I’d review a PR to do that.

As to which is faster, it depends on how many items you have and probably other things.

@SimonSapin
Copy link
Member

@SimonSapin SimonSapin commented Apr 19, 2015

It’s often hard to predict what algorithm is gonna be faster on a particular data set, the only way to know is to try and benchmark it.

@McGittyHub
Copy link

@McGittyHub McGittyHub commented Nov 27, 2017

This is a feature that I would have liked to be able to use in my code.

@mbrubeck
Copy link
Contributor

@mbrubeck mbrubeck commented Nov 27, 2017

An implementation of dedup (and also dedup_by and dedup_by_key) would be very welcome. The truncate method was added in #12, so all these methods need to do is swap duplicate elements to the back of the vector and then truncate the vector to drop them. (As mentioned above, you can use the code from std::vec for reference.)

@Thou94
Copy link

@Thou94 Thou94 commented Nov 29, 2017

I would like to work on it, but it's my first time to contribute to an open source project. I would love to get some help, if I stuck somewhere.

@jdm
Copy link
Member

@jdm jdm commented Nov 29, 2017

@Thou94 A PR to implement those methods has already been submitted in #72.

@mbrubeck
Copy link
Contributor

@mbrubeck mbrubeck commented Nov 30, 2017

Fixed by #72, and will be included in version 0.6.0 (#78).

@mbrubeck mbrubeck closed this Nov 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.