summary refs log tree commit diff
path: root/src/liballoc/collections
AgeCommit message (Collapse)AuthorLines
2020-04-17Rollup merge of #71167 - RalfJung:big-o, r=shepmasterDylan DPC-29/+28
big-O notation: parenthesis for function calls, explicit multiplication I saw `O(n m log n)` in the docs and found that really hard to parse. In particular, I don't think we should use blank space as syntax for *both* multiplication and function calls, that is just confusing. This PR makes both multiplication and function calls explicit using Rust-like syntax. If you prefer, I can also leave one of them implicit, but I believe explicit is better here. While I was at it I also added backticks consistently.
2020-04-17Implement `Clone` for `liballoc::collections::linked_list::Cursor`.Charles Lew-0/+8
2020-04-17Rollup merge of #71220 - cuviper:std_or_patterns, r=Mark-SimulacrumDylan DPC-6/+1
Dogfood or_patterns in the standard library We can start using `or_patterns` in the standard library as a step toward stabilization. cc #54883 @Centril
2020-04-16Minor fixes to doc comments of 'VecDequeue'Youngsuk Kim-6/+6
1. Changed descriptions of `fn get` & `fn get_mut`. Since both of these functions are returning references, and not the owned value, I thought the doc comments could be fixed to be consistent with doc comments of `fn front` & `fn front_mut`. 2. Other changes are minor fixes or additions for clarification. Thank you for taking a look :)
2020-04-16Dogfood or_patterns in the standard libraryJosh Stone-6/+1
2020-04-15don't specify log base in big-ORalf Jung-3/+3
2020-04-15big-O notation: parenthesis, multiplication and backticksRalf Jung-28/+27
2020-04-11Rollup merge of #70996 - ChaiTRex:master, r=AmanieuDylan DPC-0/+28
Add or_insert_with_key to Entry of HashMap/BTreeMap Going along with `or_insert_with`, `or_insert_with_key` provides the `Entry`'s key to the lambda, avoiding the need to either clone the key or the need to reimplement this body of this method from scratch each time. This is useful when the initial value for a map entry is derived from the key. For example, the introductory Rust book has an example Cacher struct that takes an expensive-to-compute lambda and then can, given an argument to the lambda, produce either the cached result or execute the lambda. --- I'm fairly new to Rust, so any optimizations, corrections to types, better names, better documentation, or whatever else would be appreciated. I'd like to thank Arnavion on freenode for helping me to implement a very similar method when I found that `or_insert_with_key` was unavailable. As a somewhat-related note, this implements https://github.com/rust-lang/rfcs/issues/1202 from 2015, so if this pull request is accepted, that should be closed.
2020-04-11Change issue number to point to tracking issueChai T. Rex-1/+1
2020-04-10Fixed doc tests for added methodsChai T. Rex-0/+1
2020-04-10Add or_insert_with_key to Entry of HashMap/BTreeMapChai T. Rex-0/+27
Going along with or_insert_with, or_insert_with_key provides the Entry's key to the lambda, avoiding the need to either clone the key or the need to reimplement this body of this method from scratch each time. This is useful when the initial value for a map entry is derived from the key. For example, the introductory Rust book has an example Cacher struct that takes an expensive-to-compute lambda and then can, given an argument to the lambda, produce either the cached result or execute the lambda.
2020-04-10Rollup merge of #70981 - ssomers:btreemap_into_into_iter, r=Mark-SimulacrumMazdak Farrokhzad-13/+13
Rearrange BTreeMap::into_iter to match range_mut. r? @Mark-Simulacrum I wondered why you catered for the optional root differently in `into_iter` than in `range_mut`.
2020-04-10Rollup merge of #70979 - ssomers:btreemap_the_alice_merton_variations, r=AmanieuMazdak Farrokhzad-4/+2
Follow up on BTreeMap comments r? @Amanieu (for the first commit)
2020-04-10Rollup merge of #70843 - ssomers:btree_drain_filter_epilogue, r=AmanieuMazdak Farrokhzad-45/+21
Remove the Ord bound that was plaguing drain_filter Now that #70795 made it superfluous. Also removes superfluous lifetime specifiers (at least I think they are).
2020-04-10Rearrange BTreeMap::into_iter to match range_mut.Stein Somers-13/+13
2020-04-09Respect the comment: no root unless the borrow type is `Mut`Stein Somers-2/+2
2020-04-09Kill comment left behind by a last minute change in #70795Stein Somers-2/+0
2020-04-08Rollup merge of #70930 - lcnr:patch-1, r=Dylan-DPCDylan DPC-1/+1
add tracking issue to `VecDeque::make_contiguous` The tracking issue is https://github.com/rust-lang/rust/issues/70929
2020-04-08add `VecDeque::make_contiguous` tracking issueBastian Kauschke-1/+1
2020-04-06BTreeMap first/last: add pop methodsStein Somers-0/+48
2020-04-06BTreeMap first/last: make examples more to the pointStein Somers-10/+12
2020-04-06BTreeMap first/last: simplify implementationsStein Somers-38/+16
2020-04-06Remove the Ord bound that was plaguing drain_filter, and superfluous lifetimesStein Somers-45/+21
2020-04-05Rollup merge of #70795 - Amanieu:btree_remove_tracking, r=Mark-SimulacrumDylan DPC-49/+64
Keep track of position when deleting from a BTreeMap This improves the performance of drain_filter and is needed for future Cursor support for BTreeMap. cc @ssomers r? @Mark-Simulacrum
2020-04-05Rollup merge of #70777 - faern:use-assoc-int-consts2, r=dtolnayDylan DPC-1/+0
Don't import integer and float modules, use assoc consts Stop importing the standard library integer and float modules to reach the `MIN`, `MAX` and other constants. They are available directly on the primitive types now. This PR is a follow up of #69860 which made sure we use the new constants in documentation. This type of change touches a lot of files, and previously all my assoc int consts PRs had collisions and were accepted only after a long delay. So I'd prefer to do it in smaller steps now. Just removing these imports seem like a good next step. r? @dtolnay
2020-04-05Apply review feedbackAmanieu d'Antras-15/+10
2020-04-05Keep track of position when deleting from a BTreeMapAmanieu d'Antras-39/+59
This improves the performance of drain_filter and is needed for future Cursor support for BTreeMap.
2020-04-05Stop importing integer modules in liballocLinus Färnstrand-1/+0
2020-04-04use ManuallyDrop instead of forget inside collectionsTrevor Spiteri-14/+13
This commit changes some usage of mem::forget into mem::ManuallyDrop in some Vec, VecDeque, BTreeMap and Box methods. Before the commit, the generated IR for some of the methods was longer, and even after optimization, some unwinding artifacts were still present.
2020-04-02Auto merge of #70362 - TimDiekmann:alloc-overhaul, r=Amanieubors-4/+5
Overhaul of the `AllocRef` trait to match allocator-wg's latest consens; Take 2 GitHub won't let me reopen #69889 so I make a new PR. In addition to #69889 this fixes the unsoundness of `RawVec::into_box` when using allocators supporting overallocating. Also it uses `MemoryBlock` in `AllocRef` to unify `_in_place` methods by passing `&mut MemoryBlock`. Additionally, `RawVec` now checks for `size_of::<T>()` again and ignore every ZST. The internal capacity of `RawVec` isn't used by ZSTs anymore, as `into_box` now requires a length to be specified. r? @Amanieu fixes rust-lang/wg-allocators#38 fixes rust-lang/wg-allocators#41 fixes rust-lang/wg-allocators#44 fixes rust-lang/wg-allocators#51
2020-04-01Rollup merge of #68770 - ssomers:btree_drain_filter, r=AmanieuDylan DPC-13/+298
BTreeMap/BTreeSet: implement drain_filter Provide an implementation of drain_filter for BTreeMap and BTreeSet. Should be optimal when the predicate picks only elements in leaf nodes with at least MIN_LEN remaining elements, which is a common case, at least when draining only a fraction of the map/set, and also when the predicate picks elements stored in internal nodes where the right subtree can easily let go of a replacement element. The first commit adds benchmarks with an external, naive implementation. to compare how much this claimed optimality-in-some-cases is actually worth.
2020-03-31Rollup merge of #69425 - lcnr:make_contiguous, r=AmanieuDylan DPC-53/+235
add fn make_contiguous to VecDeque Adds the following method to VecDeque: ```rust pub fn make_contiguous(&mut self) -> &mut [T]; ``` Taken from https://github.com/rust-lang/rust/pull/69400, after a suggestion by @CryZe https://github.com/rust-lang/rust/pull/69400#issuecomment-590216089 I am in favor of merging this instead of https://github.com/rust-lang/rust/pull/69400.
2020-03-31fix docsBastian Kauschke-1/+1
2020-03-31update `VecDeque::as_(mut)_slice` docsBastian Kauschke-4/+4
2020-03-29BTreeMap/BTreeSet: implement and test drain_filterStein Somers-13/+298
2020-03-26Remove alignment from `MemoryBlock`Tim Diekmann-8/+4
2020-03-26Fix issues from review and unsoundness of `RawVec::into_box`Tim Diekmann-7/+12
2020-03-24must_use on split_offKornel-0/+1
#70194
2020-03-22update `make_contiguous` docsBastian Kauschke-1/+3
Co-Authored-By: Amanieu d'Antras <amanieu@gmail.com>
2020-03-22document invariant of `VecDeque::as_(mut)_slice`Bastian Kauschke-0/+6
2020-03-22remove redundant closures (clippy::redundant_closure)Matthias Krüger-2/+2
2020-03-22add `fn make_contiguous` to VecDequeBastian Kauschke-53/+227
2020-03-20Simplify ensure_root_is_owned callersMark Rousskov-15/+13
This makes ensure_root_is_owned return a reference to the (now guaranteed to exist) root, allowing callers to operate on it without going through another unwrap. Unfortunately this is only rarely useful as it's frequently the case that both the length and the root need to be accessed and field-level borrows in methods don't yet exist.
2020-03-20Drop NodeHeader type from BTree codeMark Rousskov-41/+5
We no longer have a separate header because the shared root is gone; all code can work solely with leafs now.
2020-03-20Make functions dependent only on shared root avoidance safeMark Rousskov-58/+58
2020-03-20Remove shared root code and assertions from BTree nodesMark Rousskov-59/+8
2020-03-20Replace shared root with optional rootMark Rousskov-77/+112
This simplifies the node manipulation, as we can (in later commits) always know when traversing nodes that we are not in a shared root.
2020-03-14Rollup merge of #69809 - matthiaskrgr:lifetimes, r=eddybYuki Okushi-1/+1
remove lifetimes that can be elided (clippy::needless_lifetimes)
2020-03-12remove lifetimes that can be elided (clippy::needless_lifetimes)Matthias Krüger-1/+1
2020-03-12Rollup merge of #69792 - LenaWil:try_reserve_error/impl-error, r=sfacklerMazdak Farrokhzad-0/+18
Implement Error for TryReserveError I noticed that the Error trait wasn't implemented for TryReserveError. (#48043) Not sure if the error messages and code style are 100% correct, it's my first time contributing to the Rust std.