You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Any with_capacity constructor will instruct the collection to allocate enough space for the specified number of elements. Ideally this will be for exactly that many elements, but some implementation details may prevent this. Vec and VecDeque can be relied on to allocate exactly the requested amount, though.
However, the implementation actually requires that the capacity is a power of 2, taking advantage of bitmask modulo tricks. It also needs to keep a single empty slot in the buffer.
There are some use cases that would want this feature: rotate would be an O(1) operation when len == cap, which could be useful in sliding-window type applications. But it doesn't seem like something general deque usage would really care about. So probably shouldn't reimplement the whole data structure and just change the doc to not mention VecDeque here.
The text was updated successfully, but these errors were encountered:
jonas-schievink
added
C-bug
Category: This is a bug.
A-docs
Area: documentation for any part of the project, including the compiler, standard library, and tools
labels
Apr 13, 2019
gluyas
added a commit
to gluyas/rust
that referenced
this issue
Apr 15, 2019
…c-fix, r=rkruppe
Remove collection-specific `with_capacity` documentation from `std::collections`
Fixesrust-lang#59931
The style of `std::collections` module doc is very much a beginner friendly guide, and documenting niche, collection-specific behaviour feels out of place, if not brittle.
The note about `VecDeque` is outdated (see issue), and while `Vec` probably won't change its guarantees any time soon, the users who are interested in its allocation properties will find that in its own documentation.
From
std::collections
module-level doc (emphasis added):However, the implementation actually requires that the capacity is a power of 2, taking advantage of bitmask modulo tricks. It also needs to keep a single empty slot in the buffer.
playground example
There are some use cases that would want this feature: rotate would be an O(1) operation when
len == cap
, which could be useful in sliding-window type applications. But it doesn't seem like something general deque usage would really care about. So probably shouldn't reimplement the whole data structure and just change the doc to not mentionVecDeque
here.The text was updated successfully, but these errors were encountered: