about summary refs log tree commit diff
path: root/library/alloc/src/collections
AgeCommit message (Collapse)AuthorLines
2025-07-06Renamed retain_mut to retain on LinkedList as mentioned in the ACPJoshua Gentry-37/+2
2025-06-27BTreeSet: remove duplicated code by reusing `from_sorted_iter`Cheng Xu-3/+1
The method `BTreeSet::from_sorted_iter` was introduced in 49ccb7519f55bd117d2ab50b7a030637f380aec6, but it was not consistently used throughout the codebase. As a result, some code redundantly reimplemented its logic. This commit fixes the problem.
2025-06-18vec_deque tests: remove static mutMarijn Schouten-43/+13
2025-06-17Rollup merge of #142520 - hkBst:less-static-mut, r=tgross35Jacob Pratt-106/+55
alloc: less static mut + some cleanup I'm looking into https://github.com/rust-lang/rust/issues/125035 and would like some feedback on my approach.
2025-06-17linked_list tests: buff check_linksMarijn Schouten-40/+25
2025-06-16linked_list tests: less static mutMarijn Schouten-66/+30
2025-06-13Remove unneeded lifetimes from signature of BTreeSet::extract_ifDavid Tolnay-4/+4
2025-06-02Lightly tweak docs for BTree{Map,Set}::extract_ifSidney Cammeresi-7/+7
- Move explanations into comments to match style - Explain the second examples - Make variable names match the data structure
2025-05-27Unit test for Range parameter of `BTreeMap::extract_if`Sidney Cammeresi-0/+24
2025-05-27Update docs for new Range parameter to `BTreeMap::extract_if` etc.Sidney Cammeresi-4/+16
2025-05-27Update tests with Range parameter to `BTreeMap::extract_if` etc.Sidney Cammeresi-31/+31
2025-05-27Add Range parameter to `BTreeMap::extract_if` and `BTreeSet::extract_if`Sidney Cammeresi-19/+57
This change was requested in the btree_extract_if tracking issue: https://github.com/rust-lang/rust/issues/70530#issuecomment-2486566328
2025-05-25Rollup merge of #141108 - PaulDance:fix-extract_if-docs, r=Mark-SimulacrumJacob Pratt-10/+12
Docs(lib): Fix `extract_if` docs Various fixes to the documentation comments of the several `extract_if` collection methods available. It originally started with a small typo fix in `Vec`'s spotted when reading the 1.87 release notes, but then by looking at the others' for comparison in order to try determining what was the intended sentence, some inconsistencies were spotted. Therefore, some other changes are also proposed here to reduce these avoidable differences, going more and more nit-picky along the way. See the individual commits for more details about each change. `@rustbot` label T-libs A-collections A-docs
2025-05-21std: fix doctest and explain for as_slices and as_mut_slices in VecDequexizheyin-5/+28
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-17Docs(lib/extract_if): Unify example descriptionPaul Mabileau-1/+1
Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-17Docs(lib/extract_if): Unify paragraph about elements mutationPaul Mabileau-2/+2
Take the one from `BTreeMap` that seems the best-worded and most precise among the available variations. Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-17Docs(lib/extract_if): Unify paragraph about closure actionsPaul Mabileau-3/+3
Also fixes `HashSet`'s that incorrectly designated itself as a `list`. Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-17Docs(lib/coll/btm): Split `extract_if`'s first sentence from the following onesPaul Mabileau-4/+6
This also seems like a small mistake: the first main sentence is put in the same paragraph as the other two following ones while other equivalents all have it split. Therefore, do the same here. Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-07Rollup merge of #140668 - vkrivopalov:vecdeque-truncate-front, r=jhprattJacob Pratt-0/+67
Implement `VecDeque::truncate_front()` Tracking issue: #140667
2025-05-05Consistent trait bounds for ExtractIf Debug implsDavid Tolnay-15/+18
2025-05-05Implement `VecDeque::truncate_front()`Vladimir Krivopalov-0/+67
Tracking issue: #140667 Signed-off-by: Vladimir Krivopalov <vladimir.krivopalov@gmail.com>
2025-04-24Remove some unnecessary clones.Nicholas Nethercote-1/+1
I found these by grepping for `&[a-z_\.]*\.clone()`, i.e. expressions like `&a.b.clone()`, which are sometimes unnecessary clones, and also looking at clones nearby to cases like that.
2025-04-09intra-doc linkBoxy-1/+1
2025-04-09replace version placeholderBoxy-4/+4
2025-03-12Rollup merge of #138161 - HeroicKatora:heap-peek-mut-refresh, r=dtolnayMatthias Krüger-4/+78
Add PeekMut::refresh I'm not sure if this should go through ACP or not. BinaryHeap is not the most critical data structure in the standard library and it would be understandable if maintainer throughput is thus too limited to accept this PR without a proper design phase that ensures the required understanding of consequence over a longer time period. This aims to improve the useability of heaps for priority-based work queues. In certain scenarios, modifications on the most relevant or critical items are performed until a condition that determines the work items have been sufficiently addressed. For instance the criticality could be a deadline that is relaxed whenever some part of a work item is completed. Such a loop will repeatedly access the most critical item and put it back in a sorted position when it is complete. Crucially, due to the ordering invariant we know that all necessary work was performed when the completed item remains the most critical. Getting this information from the heap position avoids a (potentially more costly) check on the item state itself. A customized `drop` with boolean result would avoid up to two more comparisons performed in both the last no-op refresh and Drop code but this occurs once in each execution of the above scenario whereas refresh occurs any number of times. Also note that the comparison overhead of Drop is only taken if the element is mutably inspected to determine the end condition, i.e. not when refresh itself is the break condition.
2025-03-11Add PeekMut::refreshAurelia Molzer-4/+78
This improves the useability of heaps for priority-based work queues. In certain scenarios, modifications on the most relevant or critical items are performed until a condition that determines the work items have been sufficiently addressed. The loop will repeatedly access the most critical item and put it back in a sorted position when it is complete. Crucially, due to the ordering invariant we know that all work was performed when the completed item remains the most critical. Getting this information from the heap position avoids a (potentially more costly) check on the item state itself. A customized `drop` with boolean result would avoid up to two more comparisons performed in both the last no-op refresh and Drop code but this occurs once in each execution of the above scenario whereas refresh occurs any number of times. Also note that the comparison overhead of Drop is only taken if the element is mutably inspected to determine the end condition, i.e. not when refresh itself is the break condition.
2025-03-07Add commentsbjorn3-0/+3
2025-03-07Fully test the alloc crate through alloctestsbjorn3-1/+29
For the tests that make use of internal implementation details, we include the module to test using #[path] in alloctests now.
2025-03-06library: Use size_of from the prelude instead of importedThalia Archibald-4/+4
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80.
2025-02-25Rollup merge of #137576 - goffrie:setvalzst, r=lcnrLeón Orell Valerian Liehr-1/+1
Don't doc-comment BTreeMap<K, SetValZST, A> This otherwise shows up in documentation as an empty impl block (worse, at the *top* of the docs above the public impls).
2025-02-24Don't doc-comment BTreeMap<K, SetValZST, A>Geoffry Song-1/+1
2025-02-23stabilize extract_ifbendn-5/+4
2025-02-10Rollup merge of #136705 - compiler-errors:edition-library, r=jhprattJubilee-1/+1
Some miscellaneous edition-related library tweaks Some library edition tweaks that can be done separately from upgrading the whole standard library to edition 2024 (which is blocked on getting the submodules upgraded, for example)
2025-02-09Fix pattern matching mode changes and unsafe_op_in_unsafe_fnMichael Goulet-1/+1
2025-02-08Rustfmtbjorn3-21/+30
2025-01-30Rollup merge of #136215 - btj:patch-1, r=cuviperStuart Cook-2/+2
btree/node.rs: remove incorrect comment from pop_internal_level docs
2025-01-29btree/node.rs: pop_internal_level: does not invalidate other handlesBart Jacobs-0/+3
2025-01-28btree/node.rs: remove incorrect comment from pop_internal_level docsBart Jacobs-3/+0
2025-01-28Auto merge of #136203 - matthiaskrgr:rollup-1k0f44l, r=matthiaskrgrbors-0/+1
Rollup of 9 pull requests Successful merges: - #135869 (Make docs for AtomicUsize::from_mut platform-independent) - #135892 (-Znext-solver: "normalize" signature before checking it mentions self in `deduce_closure_signature`) - #136055 (Implement MIR const trait stability checks) - #136066 (Pass spans to `perform_locally_in_new_solver`) - #136071 ([Clippy] Add vec_reserve & vecdeque_reserve diagnostic items) - #136124 (Arbitrary self types v2: explain test.) - #136149 (Flip the `rustc-rayon`/`indexmap` dependency order) - #136173 (Update comments and sort target_arch in c_char_definition) - #136178 (Update username in build helper example) r? `@ghost` `@rustbot` modify labels: rollup
2025-01-28Rollup merge of #135367 - Urgau:unreach_pub-std-3, r=NoratriebMatthias Krüger-168/+203
Enable `unreachable_pub` lint in `alloc` This PR enables the [`unreachable_pub`](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unreachable-pub) lint as warn in the `alloc` crate. Most of changes are in the btree implementation and in tests. *The diff was mostly generated with `./x.py fix --stage 1 library/alloc/ -- --broken-code`, as well as manual edits for code in macros and in tests.* Continuation of #134286 and #135366 r? libs
2025-01-25[Clippy] Add vec_reserve & vecdeque_reserve diagnostic itemswowinter13-0/+1
2025-01-24Rollup merge of #135890 - GrigorenkoPV:deque-pop-if, r=thomccMatthias Krüger-0/+46
Implement `VecDeque::pop_front_if` & `VecDeque::pop_back_if` Tracking issue: #135889
2025-01-22Implement `VecDeque::pop_front_if` & `VecDeque::pop_back_if`Pavel Grigorenko-0/+46
2025-01-22Remove erroneous `unsafe` in `BTreeSet::upper_bound_mut`Pavel Grigorenko-4/+4
2025-01-20alloc: add `#![warn(unreachable_pub)]`Urgau-168/+203
2025-01-11Add inherent versions of MaybeUninit methods for slicesltdk-3/+1
2024-12-26Rollup merge of #134644 - kpreid:duplicates, r=Mark-SimulacrumJacob Pratt-1/+13
Document collection `From` and `FromIterator` impls that drop duplicate keys. This behavior is worth documenting because there are other plausible alternatives, such as panicking when a duplicate is encountered, and it reminds the programmer to consider whether they should, for example, coalesce duplicate keys first. Followup to #89869.
2024-12-22Specify only that duplicates are discarded, not the order.Kevin Reid-4/+5
2024-12-21Document collection `From` and `FromIterator` impls that drop duplicate keys.Kevin Reid-1/+12
This behavior is worth documenting because there are other plausible alternatives, such as panicking when a duplicate is encountered, and it reminds the programmer to consider whether they should, for example, coalesce duplicate keys first.
2024-12-21Less unwrap() in documentationKornel-2/+1