summary refs log tree commit diff
path: root/library/alloc/src/collections/btree/map
AgeCommit message (Collapse)AuthorLines
2023-06-14s/drain_filter/extract_if/ for Vec, Btree{Map,Set} and LinkedListThe 8472-28/+28
2023-06-14remove drain-on-drop behavior from BTree{Set,Map}::DrainFilter and add ↵The 8472-18/+21
#[must_use]
2023-06-13ignore core, alloc and test tests that require unwinding on panic=abortPietro Albini-0/+9
2023-05-04btree_map: `Cursor{,Mut}::peek_prev` must agreeJubilee Young-0/+19
Our `Cursor::peek_prev` and `CursorMut::peek_prev` must agree on how to behave when they are called on the "null element".
2023-04-14Rollup merge of #110244 - kadiwa4:unnecessary_imports, r=JohnTitorMatthias Krüger-2/+1
Remove some unneeded imports / qualified paths Continuation of #105537.
2023-04-12remove some unneeded importsKaDiWa-2/+1
2023-04-12Fix btree `CursorMut::insert_after` checkmarc0246-0/+64
2023-02-01BTreeMap: Add Cursor and CursorMutAmanieu d'Antras-0/+49
2023-02-01BTreeMap: Change internal insert function to return a handleAmanieu d'Antras-19/+21
This is a prerequisite for cursor support for `BTreeMap`.
2022-12-28Rollup merge of #94145 - ssomers:binary_heap_tests, r=jyn514fee1-dead-3/+3
Test leaking of BinaryHeap Drain iterators Add test cases about forgetting the `BinaryHeap::Drain` iterator, and slightly fortifies some other test cases. Consists of separate commits that I don't think are relevant on their own (but I'll happily turn these into more PRs if desired).
2022-09-26remove cfg(bootstrap)Pietro Albini-1/+0
2022-08-22Move error trait into coreJane Losare-Lusby-0/+11
2022-06-23Fix BTreeSet's range API panic message, documenttnballo-0/+33
2022-06-17comments explaining why we have and don't have ManuallyDropRalf Jung-0/+2
2022-06-16btree: avoid forcing the allocator to be a referenceRalf Jung-24/+22
2022-06-14BTreeMap: Add alloc paramJacob Hughes-24/+50
2022-06-08BTree: tweak internal commentsStein Somers-4/+5
2022-05-02Share testing utilities with non-btree test casesStein Somers-3/+3
2022-04-15chore: formattingKeita Nonaka-11/+9
2022-04-15test: add try_insert() test cases for BTreeSetKeita Nonaka-0/+15
2022-04-15test: add get_key_value() test cases for BTreeSetKeita Nonaka-0/+24
2022-04-14test: add pop_first() pop_last() test cases for BTreeSetKeita Nonaka-9/+77
2022-03-20Auto merge of #92962 - frank-king:btree_entry_no_insert, r=Amanieubors-20/+63
BTreeMap::entry: Avoid allocating if no insertion This PR allows the `VacantEntry` to borrow from an empty tree with no root, and to lazily allocate a new root node when the user calls `.insert(value)`.
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-1/+1
This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored).
2022-03-09BTreeMap::entry: Avoid allocating if no insertionFrank King-20/+63
2022-03-07BTree: remove dead data needlessly complicating insertStein Somers-3/+3
2022-02-20BTree: simplify test codeStein Somers-108/+89
2022-01-09eplace usages of vec![].into_iter with [].into_iterLucas Kent-2/+2
2021-12-10BTree: rename compile-time assertions to match library/alloc/testsStein Somers-3/+3
2021-10-15Add #[must_use] to remaining alloc functionsJohn Kugelman-13/+15
2021-10-10Add #[must_use] to conversions that move selfJohn Kugelman-10/+11
2021-10-03Auto merge of #88086 - ssomers:btree_clone_testing, r=dtolnaybors-24/+31
BTree: toughen panicky test of clone() Test did not cover the second half of `clone_subtree` and why this clones key & value first.
2021-08-18BTree: remove Ord bound from newGary Guo-1/+7
2021-08-16BTree: toughen panicky test of clone()Stein Somers-24/+31
2021-08-13Moved ui testDeadbeef-7/+0
2021-07-24Auto merge of #84111 - bstrie:hashfrom, r=joshtriplettbors-0/+7
Stabilize `impl From<[(K, V); N]> for HashMap` (and friends) In addition to allowing HashMap to participate in Into/From conversion, this adds the long-requested ability to use constructor-like syntax for initializing a HashMap: ```rust let map = HashMap::from([ (1, 2), (3, 4), (5, 6) ]); ``` This addition is highly motivated by existing precedence, e.g. it is already possible to similarly construct a Vec from a fixed-size array: ```rust let vec = Vec::from([1, 2, 3]); ``` ...and it is already possible to collect a Vec of tuples into a HashMap (and vice-versa): ```rust let vec = Vec::from([(1, 2)]); let map: HashMap<_, _> = vec.into_iter().collect(); let vec: Vec<(_, _)> = map.into_iter().collect(); ``` ...and of course it is likewise possible to collect a fixed-size array of tuples into a HashMap ([but not vice-versa just yet](https://github.com/rust-lang/rust/issues/81615)): ```rust let arr = [(1, 2)]; let map: HashMap<_, _> = std::array::IntoIter::new(arr).collect(); ``` Therefore this addition seems like a no-brainer. As for any impl, this would be insta-stable.
2021-07-15Added diagnostic items to structs and traits for ClippyxFrednet-0/+1
2021-06-30impl From<[(K, V); N]> for std::collectionsbstrie-0/+7
2021-03-18BTree: no longer search arrays twice to check OrdStein Somers-2/+0
2021-03-05Rollup merge of #82764 - m-ou-se:map-try-insert, r=AmanieuMara-0/+35
Add {BTreeMap,HashMap}::try_insert `{BTreeMap,HashMap}::insert(key, new_val)` returns `Some(old_val)` if the key was already in the map. It's often useful to assert no duplicate values are inserted. We experimented with `map.insert(key, val).unwrap_none()` (https://github.com/rust-lang/rust/issues/62633), but decided that that's not the kind of method we'd like to have on `Option`s. `insert` always succeeds because it replaces the old value if it exists. One could argue that `insert()` is never the right method for panicking on duplicates, since already handles that case by replacing the value, only allowing you to panic after that already happened. This PR adds a `try_insert` method that instead returns a `Result::Err` when the key already exists. This error contains both the `OccupiedEntry` and the value that was supposed to be inserted. This means that unwrapping that result gives more context: ```rust map.insert(10, "world").unwrap_none(); // thread 'main' panicked at 'called `Option::unwrap_none()` on a `Some` value: "hello"', src/main.rs:8:29 ``` ```rust map.try_insert(10, "world").unwrap(); // thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: // OccupiedError { key: 10, old_value: "hello", new_value: "world" }', src/main.rs:6:33 ``` It also allows handling the failure in any other way, as you have full access to the `OccupiedEntry` and the value. `try_insert` returns a reference to the value in case of success, making it an alternative to `.entry(key).or_insert(value)`. r? ```@Amanieu``` Fixes https://github.com/rust-lang/rfcs/issues/3092
2021-03-04Add tracking issue for map_try_insert.Mara Bos-3/+3
2021-03-04Implement Error for OccupiedError.Mara Bos-0/+13
2021-03-04Improve Debug implementations of OccupiedError.Mara Bos-2/+3
2021-03-04Add BTreeMap::try_insert and btree_map::OccupiedError.Mara Bos-0/+21
2021-03-03Fix ui-full-deps suiteRyan Levick-4/+4
2021-03-01Rollup merge of #81210 - ssomers:btree_fix_node_size_test, r=Mark-SimulacrumJoshua Nelson-2/+3
BTreeMap: correct node size test case for choices of B r? `@Mark-Simulacrum`
2021-02-24library: Normalize safety-for-unsafe-block commentsMiguel Ojeda-2/+2
Almost all safety comments are of the form `// SAFETY:`, so normalize the rest and fix a few of them that should have been a `/// # Safety` section instead. Furthermore, make `tidy` only allow the uppercase form. While currently `tidy` only checks `core`, it is a good idea to prevent `core` from drifting to non-uppercase comments, so that later we can start checking `alloc` etc. too. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-02-21BTreeMap: correct tests for alternative choices of BStein Somers-2/+3
2021-02-09BTreeMap: share panicky test code & test panic during clear, cloneStein Somers-127/+152
2021-02-09BTreeMap/BTreeSet: separate off code supporting testsStein Somers-85/+2