about summary refs log tree commit diff
path: root/library/alloc/src/collections/btree
AgeCommit message (Collapse)AuthorLines
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-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
2024-10-25library: consistently use American spelling for 'behavior'Ralf Jung-1/+1
2024-10-23"innermost", "outermost", "leftmost", and "rightmost" don't need hyphensJosh Triplett-4/+4
These are all standard dictionary words and don't require hyphenation.
2024-09-25Use `&raw` in the standard libraryJosh Stone-5/+5
Since the stabilization in #127679 has reached stage0, 1.82-beta, we can start using `&raw` freely, and even the soft-deprecated `ptr::addr_of!` and `ptr::addr_of_mut!` can stop allowing the unstable feature. I intentionally did not change any documentation or tests, but the rest of those macro uses are all now using `&raw const` or `&raw mut` in the standard library.
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-20/+16
2024-09-19[Clippy] Swap `map_entry` to use diagnostic items instead of pathsGnomedDev-0/+2
2024-09-18[Clippy] Swap `manual_retain` to use diagnostic items instead of pathsGnomedDev-0/+1
2024-09-07Auto merge of #129941 - BoxyUwU:bump-boostrap, r=albertlarsan68bors-2/+2
Bump boostrap compiler to new beta Accidentally left some comments on the update cfgs commit directly xd
2024-09-05Rollup merge of #101339 - the8472:ci-randomize-debug, r=Mark-SimulacrumMatthias Krüger-1/+1
enable -Zrandomize-layout in debug CI builds This builds rustc/libs/tools with `-Zrandomize-layout` on *-debug CI runners. Only a handful of tests and asserts break with that enabled, which is promising. One test was fixable, the rest is dealt with by disabling them through new cargo features or compiletest directives. The config.toml flag `rust.randomize-layout` defaults to false, so it has to be explicitly enabled for now.
2024-09-03replace placeholder versionBoxy-2/+2
2024-08-31when -Zrandomize-layout is enabled disable alloc test testing internal ↵The 8472-1/+1
struct sizes
2024-08-31Fixed typos in btree map docsranger-ross-4/+4
2024-08-07Rollup merge of #128261 - clarfonthey:iter-default, r=dtolnayMatthias Krüger-0/+28
impl `Default` for collection iterators that don't already have it There is a pretty strong precedent for implementing `Default` for collection iterators, and this does so for some where this implementation was missed. I don't think this needs a separate ACP (since this precedent already exists, and these feel like they were just missed), however, it *will* need an FCP since these implementations are instantly stable.
2024-08-05Rollup merge of #128309 - kmicklas:btreeset-cursor, r=AmanieuMatthias Krüger-1/+582
Implement cursors for `BTreeSet` Tracking issue: https://github.com/rust-lang/rust/issues/107540 This is a straightforward wrapping of the map API, except that map's `CursorMut` does not make sense, because there is no value to mutate. Hence, map's `CursorMutKey` is wrapped here as just `CursorMut`, since it's unambiguous for sets and we don't normally speak of "keys". On the other hand, I can see some potential for confusion with `CursorMut` meaning different things in each module. I'm happy to take suggestions to improve that. r? ````@Amanieu````
2024-08-01Fix mutability in doc tests for `BTreeSet` cursorsKen Micklas-10/+10
2024-08-01Introduce `Cursor`/`CursorMut`/`CursorMutKey` thrichotomy for `BTreeSet` ↵Ken Micklas-16/+194
like map API