about summary refs log tree commit diff
path: root/src/liballoc/collections
AgeCommit message (Collapse)AuthorLines
2019-11-13Auto merge of #65637 - ssomers:master, r=scottmcmbors-11/+214
proposal for BTreeMap/Set min/max, #62924 - Which pair of names: #62924 lists the existing possibilities min/max, first/last, (EDIT) front/back, peek(/peek_back?). Iterators have next/next_back or next/last. I'm slightly in favour of first/last because min/max might suggest they search over the entire map, and front/back pretends they are only about position. - Return key only instead of pair like iterator does? - If not, then keep the _key_value suffix? ~~Also provide variant with mutable value? But there is no such variant for get_key_value.~~ - Look for and upgrade more usages of `.iter().next()` and such in the libraries? I only upgraded the ones I contributed myself, all very recently.
2019-11-11Auto merge of #65933 - crgl:vec-deque-truncate, r=alexcrichtonbors-4/+63
Use ptr::drop_in_place for VecDeque::truncate and VecDeque::clear This commit allows `VecDeque::truncate` to take advantage of its (largely) contiguous memory layout and is consistent with the change in #64432 for `Vec`. As with the change to `Vec::truncate`, this changes both: - the drop order, from back-to-front to front-to-back - the behavior when dropping an element panics For consistency, it also changes the behavior when dropping an element panics for `VecDeque::clear`. These changes in behavior can be observed. This example ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=d0b1f2edc123437a2f704cbe8d93d828)) ```rust use std::collections::VecDeque; fn main() { struct Bomb(usize); impl Drop for Bomb { fn drop(&mut self) { panic!(format!("{}", self.0)); } } let mut v = VecDeque::from(vec![Bomb(0), Bomb(1)]); std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { v.truncate(0); })); std::mem::forget(v); } ``` panics printing `1` today and succeeds. `v.clear()` panics printing `0` today and succeeds. With the change, `v.clear()`, `v.truncate(0)`, and dropping the `VecDeque` all panic printing `0` first and then abort with a double-panic printing `1`. The motivation for this was making `VecDeque::truncate` more efficient since it was used in the implementation of `VecDeque::clone_from` (#65069), but it also makes behavior more consistent within the `VecDeque` and with `Vec` if that change is accepted (this probably doesn't make sense to merge if not). This might need a crater run and an FCP as well.
2019-11-07Rollup merge of #66117 - olegnn:fixed_linked_list_marker, r=RalfJungYuki Okushi-1/+1
Fixed PhantomData markers in Arc and Rc Include owned internal structs in `PhantomData` markers in `Arc` (`PhantomData<T>` => `PhantomData<ArcInner<T>>`) and `Rc` (`PhantomData<T>` => `PhantomData<RcBox<T>>`).
2019-11-05Reverted PhantomData in LinkedList, fixed PhantomData markers in Rc and ArcOleg Nosov-2/+2
2019-11-05LinkedList: PhantomData<Box<Node<T>>> => PhantomData<T>Oleg Nosov-3/+3
2019-11-05Rollup merge of #65574 - tshepang:linked-list-disclaimer, r=CentrilPietro Albini-7/+7
docs: improve disclaimer regarding LinkedList
2019-10-31docs: improve disclaimer regarding LinkedListTshepang Lekhonkhobe-7/+7
2019-10-29Use truncate(0) in VecDeque clearCharles Gleason-1/+1
2019-10-29Add test for VecDeque truncateCharles Gleason-0/+35
2019-10-29Use ptr::drop_in_place in VecDeque truncateCharles Gleason-2/+25
2019-10-29Match docs for VecDeque truncate to Vec truncateCharles Gleason-1/+2
2019-10-25fix doctestHideki Sekine-10/+4
2019-10-25Simplify .drain_sorted() and its doc.Hideki Sekine-45/+40
2019-10-25Add .into_iter_sorted() and .drain_sorted()Hideki Sekine-1/+140
* `.drain_sorted()` doc change suggested by @KodrAus
2019-10-23proposal for access to BTreeMap/BTreeSet first/last, #62924Stein Somers-11/+214
2019-10-22Apply clippy::needless_return suggestionsMateusz Mikuła-1/+1
2019-10-19Rollup merge of #65226 - ssomers:master, r=blussMazdak Farrokhzad-120/+119
BTreeSet symmetric_difference & union optimized No scalability changes, but: - Grew the cmp_opt function (shared by symmetric_difference & union) into a MergeIter, with less memory overhead than the pairs of Peekable iterators now, speeding up ~20% on my machine (not so clear on Travis though, I actually switched it off there because it wasn't consistent about identical code). Mainly meant to improve readability by sharing code, though it does end up using more lines of code. Extending and reusing the MergeIter in btree_map might be better, but I'm not sure that's possible or desirable. This MergeIter probably pretends to be more generic than it is, yet doesn't declare to be an iterator because there's no need to, it's only there to help construct genuine iterators SymmetricDifference & Union. - Compact the code of #64820 by moving if/else into match guards. r? @bluss
2019-10-18BTreeSet symmetric_difference & union optimized, cleanedStein Somers-120/+119
2019-10-10Override nth for VecDeque Iter and IterMutCharles Gleason-0/+20
2019-10-10Add tests for VecDeque clone_fromCharles Gleason-0/+23
2019-10-10Implement Clone::clone_from for VecDequeCharles Gleason-2/+79
2019-10-03Rollup merge of #64975 - crgl:clone-from-linked-list, r=blussMazdak Farrokhzad-0/+56
Implement Clone::clone_from for LinkedList See #28481. This represents a substantial speedup when the list sizes are comparable, and shouldn't ever be significantly worse. Technically split_off is doing an unnecessary search, but the code is hopefully cleaner as a result. I'm happy to rework anything that needs to be changed as well!
2019-10-02Add test for LinkedList clone_fromCharles Gleason-0/+43
2019-10-02Use zipped iterators in clone_from for LinkedListCharles Gleason-2/+2
2019-10-01Implement Clone::clone_from for LinkedListCharles Gleason-0/+13
2019-10-01Rollup merge of #64912 - lzutao:unneeded-main-doc, r=jonas-schievinkMazdak Farrokhzad-2/+0
Remove unneeded `fn main` blocks from docs ## [No whitespace diff](https://github.com/rust-lang/rust/pull/64912/files?w=1)
2019-10-01BTreeSet intersection, difference & is_subnet optimizationsStein Somers-75/+155
2019-10-01Remove unneeded `fn main` blocks from docsLzu Tao-2/+0
2019-09-27Stabilize map_get_key_value featureLzu Tao-2/+1
2019-09-16Auto merge of #64383 - pcpthm:btreeset-size-hint, r=dtolnaybors-22/+22
Improve BTreeSet::Intersection::size_hint A comment on `IntersectionInner` mentions `small_iter` should be smaller than `other_iter` but this condition is broken while iterating because those two iterators can be consumed at a different rate. I added a test to demonstrate this situation. <del>I made `small_iter.len() < other_iter.len()` always true by swapping two iterators when that condition became false. This change affects the return value of `size_hint`. The previous result was also correct but this new version always returns smaller upper bound than the previous version.</del> I changed `size_hint` to taking minimum of both lengths of iterators and renamed fields to `a` and `b` to match `Union` iterator.
2019-09-16Improve BTreeSet::Intersection::size_hintpcpthm-22/+22
The commented invariant that an iterator is smaller than other iterator was violated after next is called and two iterators are consumed at different rates.
2019-09-06A few cosmetic improvements to code & comments in liballoc and libcoreAlexander Regueiro-2/+2
2019-08-30Rollup merge of #63684 - GrayJack:const_list_new, r=CentrilMazdak Farrokhzad-1/+1
Constify LinkedList new function Change the `LinkedList::new()` function to become a const fn, allowing the use in constant context.
2019-08-22Fix formatting.Tomasz Różański-1/+1
2019-08-22Fix a typo.Tomasz Różański-1/+1
2019-08-18Auto merge of #63045 - Rosto75:master, r=jonas-schievinkbors-43/+43
Change the placement of two functions. Right now, the order is as follows: `pop_front()` `push_front()` `push_back()` `pop_back()` `swap_remove_back()` `swap_remove_front()` I believe it would be more natural, and easier to follow, if we place `pop_back()` right after the `pop_front()`, and `swap_remove_back()` after the `swap_remove_front()` like this: `pop_front()` `pop_back()` `push_front()` `push_back()` `swap_remove_front()` `swap_remove_back()` The rest of the documentation (at least in this module) adheres to the same logic, where the 'front' function always precedes its 'back' equivalent.
2019-08-18Constify LinkedList new functionGrayJack-1/+1
2019-08-16Add the Layout of the failed allocation to TryReserveError::AllocErrorSimon Sapin-11/+14
… and add a separately-unstable field to force non-exhaustive matching (`#[non_exhaustive]` is no implemented yet on enum variants) so that we have the option to later expose the allocator’s error value. CC https://github.com/rust-lang/wg-allocators/issues/23
2019-08-16Rename CollectionAllocError to TryReserveErrorSimon Sapin-13/+13
2019-08-14Auto merge of #63534 - Mark-Simulacrum:stage0-bump, r=Centrilbors-3/+3
Bump to 1.39 r? @Centril
2019-08-14Handle cfg(bootstrap) throughoutMark Rousskov-3/+3
2019-08-12Apply suggestions from code reviewObserver42-2/+2
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-08-12Document From trait for BinaryHeapObserver42-0/+3
2019-08-02Remove some more `cfg(test)`sVadim Petrochenkov-1/+0
2019-08-02liballoc: Unconfigure tests during normal buildVadim Petrochenkov-656/+650
Remove additional libcore-like restrictions from liballoc, turns out the testing works ok if the tests are a part of liballoc itself.
2019-07-28Rollup merge of #63061 - Centril:constantly-improving, r=scottmcmMazdak Farrokhzad-26/+14
In which we constantly improve the Vec(Deque) array PartialEq impls Use the same approach as in https://github.com/rust-lang/rust/pull/62435 as sanctioned by https://github.com/rust-lang/rust/issues/61415#issuecomment-504155110. r? @scottmcm
2019-07-28Rollup merge of #62806 - mati865:clippy, r=TimNNMazdak Farrokhzad-7/+7
Fix few Clippy warnings
2019-07-28Use const generics for some VecDeque impls.Mazdak Farrokhzad-26/+14
2019-07-27Change the placement of two functions.Tomasz Różański-43/+43
Right now, the order is as follows: `pop_front()` `push_front()` `push_back()` `pop_back()` `swap_remove_back()` `swap_remove_front()` I believe it would be more natural, and easier to follow, if we place `pop_back()` right after the `pop_front()`, and `swap_remove_back()` after the `swap_remove_front()` like this: `pop_front()` `pop_back()` `push_front()` `push_back()` `swap_remove_front()` `swap_remove_back()` The rest of the documentation (at least in this module) adheres to the same logic, where the 'front' function always precedes its 'back' equivalent.
2019-07-25Auto merge of #60340 - mgeier:cap-vs-capacity, r=alexcrichtonbors-17/+17
Rename .cap() methods to .capacity() As mentioned in #60316, there are a few `.cap()` methods, which seem out-of-place because such methods are called `.capacity()` in the rest of the code. This PR renames them to `.capacity()` but leaves `RawVec::cap()` in there for backwards compatibility. I didn't try to mark the old version as "deprecated", because I guess this would cause too much noise.