-
Notifications
You must be signed in to change notification settings - Fork 292
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
Implemented drain_filter for HashMap #135
Conversation
97f74b0
to
d5f0b29
Compare
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.
My main concern with this implementation is that the behavior of the returned iterator doesn't match Vec::drain_filter
or LinkedList::drain_filter
when dropped. It should continue running the predicate function on all remaining elements instead of just leaving unprocessed elements in the table.
Would I have to add a separate type with its own drop implementation? |
Yes a separate |
984fd53
to
66bda4e
Compare
Can you add a drop guard like in rust-lang/rust#67290. After that it should be good to go. |
I've added the guard, but will wait until the embedded stuff gets fixed |
@bors r+ |
📌 Commit 9598fc8 has been approved by |
🔒 Merge conflict This pull request and the master branch diverged in a way that cannot be automatically merged. Please rebase on top of the latest master branch, and let the reviewer approve again. How do I rebase?Assuming
You may also read Git Rebasing to Resolve Conflicts by Drew Blessing for a short tutorial. Please avoid the "Resolve conflicts" button on GitHub. It uses Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how Error message
|
☔ The latest upstream changes (presumably #132) made this pull request unmergeable. Please resolve the merge conflicts. |
Drain filter is as described in the doc comments. The implementation is based almost entirely on retain's implementation, as per `amanieu`'s suggestion. I messed around with the lifetimes, as I'm not entirely familiar with the unsafe `iter` on the raw table, but since we're now using a lazy iterator, the predicate must be valid for as long as the borrow on the table. I also annotated the function with a `#[must_use]`, otherwise the drain would have no effect. Please let me know if there are any other additions before this change can be added. Thanks!
Fixed clippy lint (added tab and spaced out `=(K,V)` => `= (K, V)`). Also made the test more explicit. Edit: I've finally installed clippy rather than checking Travis.
The previous implementation did not match vec's drain filter's drop semantics. As per `amanieu`'s suggestion, added a DrainFilter which implements drop so that it removes the items which don't satisfy the predicate.
Is this good to go? |
Sorry, I don't get email notifications when you force-push. @bors r+ |
📌 Commit 0a65d86 has been approved by |
Implemented drain_filter for HashMap #134 Drain filter is as described in the doc comments. The implementation is based almost entirely on retain's implementation, as per `amanieu`'s suggestion. I messed around with the lifetimes, as I'm not entirely familiar with the unsafe `iter` on the raw table, but since we're now using a lazy iterator, the predicate must be valid for as long as the borrow on the table. I also annotated the function with a `#[must_use]`, otherwise the drain would have no effect. Please let me know if there are any other additions before this change can be added. Thanks! Edit: I also realize this could be added to hashset, let me know if I should add that as well, and if there are other tests that need to be updated.
☀️ Test successful - checks-travis |
#134
Drain filter is as described in the doc comments.
The implementation is based almost entirely on retain's implementation, as per
amanieu
'ssuggestion.
I messed around with the lifetimes, as I'm not entirely familiar with the unsafe
iter
on the raw table, but since we're now using a lazy iterator, the predicate must be valid for as
long as the borrow on the table.
I also annotated the function with a
#[must_use]
, otherwise the drain would have no effect.Please let me know if there are any other additions before this change can be added.
Thanks!
Edit:
I also realize this could be added to hashset, let me know if I should add that as well,
and if there are other tests that need to be updated.