summary refs log tree commit diff
path: root/library/alloc/src/collections/btree/map
AgeCommit message (Collapse)AuthorLines
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
2021-02-06BTreeMap: remove Ord bound where it is absent elsewhereStein Somers-2/+15
2021-02-06Rollup merge of #81610 - ssomers:btree_emphasize_ord_bound, r=dtolnayMara Bos-0/+28
BTreeMap: make Ord bound explicit, compile-test its absence Most `BTreeMap` and `BTreeSet` members are subject to an `Ord` bound but a fair number of methods are not. To better convey and perhaps later tune the `Ord` bound, make it stand out in individual `where` clauses, instead of once far away at the beginning of an `impl` block. This PR does not introduce or remove any bounds. Also adds compilation test cases checking that the bound doesn't creep in unintended on the historically unbounded methods.
2021-02-04Revert "Avoid leaking block expression values"Felix S. Klock II-1/+1
This reverts commit 4fef39113a514bb270f5661a82fdba17d3e41dbb.
2021-02-02BTreeMap: make Ord bound explicit, compile-test its absenceStein Somers-0/+28
2021-01-19BTreeMap: compile-test all borrowing interfaces and test more chaotic orderStein Somers-1/+87
2020-12-28Rollup merge of #80353 - ssomers:btree_test_split_off, r=Mark-SimulacrumDylan DPC-1/+19
BTreeMap: test split_off (and append) more thoroughly Using DeterministicRng as a poor man's property based testing rig. r? ``@Mark-Simulacrum``
2020-12-26Auto merge of #80354 - ssomers:btree_test_compact, r=Mark-Simulacrumbors-8/+32
BTreeMap: test full nodes a little more r? `@Mark-Simulacrum`
2020-12-24BTreeMap: test full nodes a little moreStein Somers-8/+32
2020-12-24BTreeMap: test split_off (and append) more thoroughlyStein Somers-1/+19