-
Notifications
You must be signed in to change notification settings - Fork 13.9k
[hashmap] Adds drain: a way to sneak out the elements while clearing a map.
#19946
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
|
Let's please hold off merging this until rust-lang/rfcs#509 is merged as well (but review is fine!) |
src/libstd/collections/hash/table.rs
Outdated
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.
nit: debug_assert_eq!
|
cc @aturon this is what we discussed on IRC yesterday. |
|
cc @thestinger for Vec changes. RingBuf/Vec .drain has been added if y'all want to review that too! |
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.
<3
|
BinaryHeap is done now, too. Not sure who "owns" that (and ringbuf too, for that matter), but someone should cc them. |
src/libcollections/vec.rs
Outdated
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 don't think this deprecation is in the RFC. It should probably be added.
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.
Unsure if this is strictly desirable. MoveItems in theory lets you move the collection to somewhere else by passing around an iterator.
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.
Yeah that's why I'm thinking it should be added to the RFC so people can debate it.
|
RingBuf is primarily authored by @csherratt. BinaryHeap hasn't really had any heavy work done on it in a while. Pretty simple collection relatively speaking. |
src/libcollections/binary_heap.rs
Outdated
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.
s/BinarHeap/BinaryHeap
|
I take it back, @apasel422 is in charge of BinaryHeap forever now. |
src/libcollections/ring_buf.rs
Outdated
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.
This should be ///
0c721de to
fcfbefb
Compare
|
This has been rebased, and I believe all review comments have been addressed. r? @gankro |
fcfbefb to
9ccd998
Compare
|
The changes to ringbuf LGTM. |
src/libcollections/binary_heap.rs
Outdated
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.
Word on high from lord @aturon is that these should be called Drain (as Iterators should be named after their creation method -- Iter, IterMut, IntoIter.
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.
All hail.
9ccd998 to
0925212
Compare
src/libcollections/ring_buf.rs
Outdated
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.
Awkward sentence. Either have a period after iterator, or just have "... iterator that clears the..."
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.
Examples
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.
All the other docs in this file say "Example", but in other files it says "Examples" even when there's only one test.
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.
New convention is examples per the rule of @steveklabnik; anything else is out of date.
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.
Even when the english language disagrees? afaik singular forms of nouns should be used when there's only one.
|
Ok, done my full pass. |
|
Moi aussi. |
|
r=me with fixed doc + squash |
…aring. It is useful to move all the elements out of some collections without deallocating the underlying buffer. It came up in IRC, and this patch implements it as `drain`. This has been discussed as part of RFC 509. r? @gankro cc: @frankmcsherry
992eeef to
d57f259
Compare
It is useful to move all the elements out of a hashmap without deallocating the underlying buffer. It came up in IRC, and this patch implements it as `drain`. r? @gankro cc: @frankmcsherry

It is useful to move all the elements out of a hashmap without deallocating
the underlying buffer. It came up in IRC, and this patch implements it as
drain.r? @gankro
cc: @frankmcsherry