about summary refs log tree commit diff
path: root/library/alloc/src/collections/btree
AgeCommit message (Collapse)AuthorLines
2025-09-29Use `Iterator::eq` and (dogfood) `eq_by` in compiler and libraryYotam Ofek-1/+1
2025-09-26Update CURRENT_RUSTC_VERSION post-bumpMark Rousskov-10/+10
2025-09-25Rollup merge of #146859 - cammeresi:btree-alloc-20250920, r=joboetMatthias Krüger-2/+13
BTreeMap: Don't leak allocators when initializing nodes Memory was allocated via `Box::leak` and thence intended to be tracked and deallocated manually, but the allocator was also leaked, not tracked, and never dropped. Now it is dropped immediately. According to my reading of the `Allocator` trait, if a copy of the allocator remains live, then its allocations must remain live. Since the B-tree has a copy of the allocator that will only be dropped after the nodes, it's safe to not store the allocator in each node (which would be a much more intrusive change). Fixes: rust-lang/rust#106203
2025-09-24BTreeMap: Don't leak allocators when initializing nodesSidney Cammeresi-2/+13
Memory was allocated via `Box::leak` and thence intended to be tracked and deallocated manually, but the allocator was also leaked, not tracked, and never dropped. Now it is dropped immediately. According to my reading of the `Allocator` trait, if a copy of the allocator remains live, then its allocations must remain live. Since the B-tree has a copy of the allocator that will only be dropped after the nodes, it's safe to not store the allocator in each node (which would be a much more intrusive change).
2025-09-21btree InternalNode::new safety commentsMarijn Schouten-2/+3
2025-09-19Add unstable attribute to BTreeMap-related allocator genericsSidney Cammeresi-2/+11
Although these types aren't directly constructable externally, since they're pub, I think this omission was an oversight.
2025-09-19btree: safety comments for init and newMarijn Schouten-1/+7
2025-09-17Rollup merge of #144871 - Kivooeo:btree_entry_insert-stabilize, r=jhprattStuart Cook-4/+2
Stabilize `btree_entry_insert` feature This stabilises `btree_map::VacantEntry::insert_entry` and `btree_map::Entry::insert_entry`, following the FCP in [tracking issue](https://github.com/rust-lang/rust/issues/65225). New stable API: ```rust impl<'a, K: Ord, V, A: Allocator + Clone> Entry<'a, K, V, A> { pub fn insert_entry(self, value: V) -> OccupiedEntry<'a, K, V, A>; } impl<'a, K: Ord, V, A: Allocator + Clone> VacantEntry<'a, K, V, A> { pub fn insert_entry(mut self, value: V) -> OccupiedEntry<'a, K, V, A>; } ``` (FCP ended almost a year ago, so if it's needed for process we could rerun it) Closes: https://github.com/rust-lang/rust/issues/65225
2025-08-27Stabilize BTree{Map,Set}::extract_ifSidney Cammeresi-12/+10
2025-08-26Rollup merge of #144373 - hkBst:remove-deprecated-1, r=jhprattGuillaume Gomez-4/+0
remove deprecated Error::description in impls [libs-api permission](https://github.com/rust-lang/libs-team/issues/615#issuecomment-3074045829) r? `@cuviper` or `@jhpratt`
2025-08-26remove deprecated Error::description in implsMarijn Schouten-4/+0
2025-08-24Prevent confusion with insertion-ordered maps.Marijn Schouten-2/+3
2025-08-24focus more on ordered aspect and restore old commentsMarijn Schouten-13/+45
2025-08-24Dial down detail of B-tree descriptionMarijn Schouten-24/+5
fixes 134088, though it is a shame to lose some of this wonderful detail.
2025-08-09`{BTree,Hash}Map`: add "`Entry` API" section headingAda Alakbarova-0/+2
2025-08-04Correct the use of `must_use` on btree::IterMutJonathan Brouwer-1/+1
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-04remove gatesKivooeo-4/+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-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-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-05Consistent trait bounds for ExtractIf Debug implsDavid Tolnay-13/+11
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-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-24Don't doc-comment BTreeMap<K, SetValZST, A>Geoffry Song-1/+1
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-6/+10
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-28Rollup merge of #135367 - Urgau:unreach_pub-std-3, r=NoratriebMatthias Krüger-167/+202
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-22Remove erroneous `unsafe` in `BTreeSet::upper_bound_mut`Pavel Grigorenko-4/+4
2025-01-20alloc: add `#![warn(unreachable_pub)]`Urgau-167/+202
2025-01-11Add inherent versions of MaybeUninit methods for slicesltdk-3/+1
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-11-27Fill in a `BTreeSet::entry` exampleJosh Stone-1/+31
2024-11-27Add a tracking issue for `btree_set_entry`Josh Stone-20/+20
2024-11-27Add `BTreeSet` entry APIs to match `HashSet`Josh Stone-2/+500
* `fn get_or_insert(&mut self, value: T) -> &T` * `fn get_or_insert_with<Q: ?Sized, F>(&mut self, value: &Q, f: F) -> &T` * `fn entry(&mut self, value: T) -> Entry<'_, T, A>` (+ `Entry` APIs)
2024-11-26Rollup merge of #133042 - cuviper:btreemap-insert_entry, r=AmanieuMichael Goulet-31/+76
btree: add `{Entry,VacantEntry}::insert_entry` This matches the recently-stabilized methods on `HashMap` entries. I've reused tracking issue #65225 for now, but we may want to split it.
2024-11-24Auto merge of #132597 - lukas-code:btree-plug-leak, r=jhprattbors-2/+64
btree: don't leak value if destructor of key panics This PR fixes a regression from https://github.com/rust-lang/rust/pull/84904. The `BTreeMap` already attempts to handle panicking destructors of the key-value pairs by continuing to execute the remaining destructors after one destructor panicked. However, after #84904 the destructor of a value in a key-value pair gets skipped if the destructor of the key panics, only continuing with the next key-value pair. This PR reverts to the behavior before #84904 to also drop the corresponding value if the destructor of a key panics. This avoids potential memory leaks and can fix the soundness of programs that rely on the destructors being executed (even though this should not be relied upon, because the std collections currently do not guarantee that the remaining elements are dropped after a panic in a destructor). cc `@Amanieu` because you had opinions on panicking destructors
2024-11-18Improve `{BTreeMap,HashMap}::get_key_value` docs.Nicholas Nethercote-4/+42
They are unusual methods. The docs don't really describe the cases when they might be useful (as opposed to just `get`), and the examples don't demonstrate the interesting cases at all. This commit improves the docs and the examples.
2024-11-14btree: add `{Entry,VacantEntry}::insert_entry`Josh Stone-31/+76
This matches the recently-stabilized methods on `HashMap` entries. I've reused tracking issue #65225 for now, but we may want to split it.
2024-11-13btree: simplify the backdoor between set and mapJosh Stone-48/+11
The internal `btree::Recover` trait acted as a private API between `BTreeSet` and `BTreeMap`, but we can use `pub(_)` restrictions these days, and some of the methods don't need special handling anymore. * `BTreeSet::get` can use `BTreeMap::get_key_value` * `BTreeSet::take` can use `BTreeMap::remove_entry` * `BTreeSet::replace` does need help, but this now uses a `pub(super)` method on `BTreeMap` instead of the trait. * `btree::Recover` is now removed.
2024-11-04btree: don't leak value if destructor of key panicsLukas Markeffsky-2/+64