-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Collections Reform Part 2 #509
Conversation
We can do append by just having a |
``` | ||
/// Gets a slice over all the elements in the RingBuf. This may require shifting | ||
/// all the elements to make this possible. | ||
pub fn to_slice(&'a self) -> &'a [T] |
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.
Wouldn’t this require &mut self
to allow shifting the elements inside?
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.
Oops, yes.
I prefer It's also important to note that whatever design we choose should be mirrored in |
|
||
* Stabilize `front`/`back`/`front_mut`/`back_mut` for peeking on the ends of Deques | ||
|
||
* Explicitly specify HashMap's iterators to be non-deterministic between iterations. This would |
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.
It seems like this is hacking around the fact that there are types that want to implement ExactSizeIterator
but not DoubleEndedIterator
. Why don't we clean up that API?
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.
Most things that care about ExactSize also care about DoubleEnded, so I'm not sure if that's totally helpful. I agree that it's a borderline abuse to impl DoubleEnded on an "unordered" sequence, though.
Passing thought: should |
Perhaps rename |
With the PR rust#19715 I raised the question whether |
based around the largest index they have set, and not the number of elements they contain. | ||
One could instead opt for `reserve_len` or | ||
`reserve_capacity`, which are effectively the same method, but with an off-by-one. That is, | ||
`reserve_len(x)` == reserve_index(x - 1)`. `reserve_len` would have the benefit of returning 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.
Just a nitpicking; markup error here.
`reserve_len(x)` == reserve_index(x - 1)`
@aturon And I sat down this afternoon and played a little marry/murder/make-out with libcollections. As a result major update:
|
/// | ||
/// Calls either `grow()` or `truncate()` depending on whether `new_len` | ||
/// is larger than the current value of `len()` or not. | ||
pub fn resize(&mut self, new_len: uint, value: T) where T: Clone |
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.
Out of curiosity, could you explain a little more the rationale for including this convenience method? I'm not sure I've personally ever needed it, but I may just be in a different line of work!
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 is something a few people has asked for. I don't have a strong desire/motivation for it, but I thought I would give it a fair try out in this RFC.
Asked for in rust-lang/rust#19104 (comment)
so maybe @nodakai can give a better justification.
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.
Ah ok, I may be forgetting, but do we have a number of other convenience methods like this on collections? I thought we had pared it back to a fairly bare-bones sense.
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.
If one wants to ensure that a vector is exactly 10 items long, this is the best method to call since it will work right even if the vector is currently 9 or 11 items long.
IMO grow
and truncate
are the convenience methods, not resize
.
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.
It would be worth looking at what the C++ std::vector
provides: http://en.cppreference.com/w/cpp/container/vector
(Spoiler: It's only resize
.)
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.
@Valloric But growing and shrinking really are very different operations. resize
necessarily must branch on whether to grow or shrink, whereas grow and truncate don't.
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.
@Valloric it would be difficult to remove truncate
as you can't always manifest a T
to call resize to truncate. C++ looks like it leverages overloading as well to provide some more functionality which we may not be able to match exactly.
This looks awesome @gankro, nice work! |
@thestinger: for the sake of transparency, I feel obligated to notify you that the current draft of this RFC is recommending the removal of Tree*, Trie*, LruCache, bitflags!, and EnumSet from the standard library. I believe you were opposed to this in the past. |
* Unstable: Bitv, BitvSet, VecMap | ||
* Move to [collect-rs](https://github.com/Gankro/collect-rs/) for incubation: | ||
EnumSet, bitflags!, LruCache, TreeMap, TreeSet, TrieMap, TrieSet | ||
|
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.
Do you think DList is ready? It's unclear if it is near its final form.
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.
And why do you think bitflags isn't ready? I agree about other collections.
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.
Collections Reform 1 already proposed cutting out a lot of DList's methods, so it's going to have a pretty minimal/uncontroversial interface.
As for bitflags, I'll leave that to @aturon
Add drain, and link to WIP implementations.
Added a |
This pull request: *Renames `BinaryHeap::top` to `BinaryHeap::peek` *Stabilizes `front/back/front_mut/back_mut` in `DList` and `RingBuf` *Stabilizes `swap` in `RingBuf` in accordance with rust-lang/rfcs#509. Note that this PR does not address `Bitv::{get,set}` or HashMap's iterators, nor does it move `std::vec` to `std::collections::vec`, all of which still need to be done. Because of the method renaming, this is a [breaking-change].
What did you intend w.r.t ExactSizeIterator and DoubleEndedIterator? I'm against implementing traits just because it's possible, with the hash maps and sets it doesn't seem useful at all. Maybe ExactSizeIterator on its own if it is untangled from DEI, but even there I don't really know any real use. |
Implement `reserve_len` and `reserve_len_exact` for `VecMap` in accordance with rust-lang/rfcs#509.
This PR deprecates the `DList::ListInsertion` trait, in accordance with rust-lang/rfcs#509. The functions which were previously part of the ListInsertion impl for `DList::IterMut` have been moved to be inherent methods on the iterator itself, and appropriate doctests have been added.
This commit takes a second pass through the `vec` module to stabilize its API. The changes are as follows: **Stable**: * `dedup` * `from_raw_parts` * `insert` * `into_iter` * `is_empty` * `remove` * `reserve_exact` * `reserve` * `retain` * `swap_remove` * `truncate` **Deprecated**: * `from_fn`, `from_elem`, `grow_fn` and `grow`, all deprecated in favor of iterators. See rust-lang/rfcs#509 * `partition`, `partitioned`, deprecated in favor of a new, more general iterator consumer called `partition`. * `unzip`, deprecated in favor of a new, more general iterator consumer called `unzip`. A few remaining methods are left at experimental status. [breaking-change]
Is it possible to amend the RFC to keep .merge() on DList? It seems absurd to add new "allocation-free" method to DList while removing others like .merge(). I'm mostly confused by the cluelessness of the deprecation message "Use other methods on IterMut"; it would be better to be more honest and tell the user there is no replacement. |
I assure you |
Oh no wait, it totally did! I misread the source. |
Implements the `append()` and `split_off()` methods proposed by the collections reform part 2 RFC. RFC: rust-lang/rfcs#509 Tracking issue: #19986
I was told to leave a comment here instead of opening a new issue: Please consider renaming string::push_str() to string::concat(). Push_X() in the context of a collection means X will be added to the container as a single entity. Hence push_str() is meaningless for strings since a string can only contain characters (char != [char]). If it is too late to rename then consider adding a method called concat() anyway. Also consider renaming Vec::push_all() to Vec::concat() so that the name is consistent with String::concat(). |
This RFC shores up the finer details of collections reform. In particular, where the previous RFC
focused on general conventions and patterns, this RFC focuses on specific APIs. It also patches
up any errors that were found during implementation of part 1. Some of these changes
have already been implemented, and simply need to be ratified.
rendered