about summary refs log tree commit diff
path: root/library/alloc/src/collections
AgeCommit message (Collapse)AuthorLines
2021-02-23BTree: fix untrue safetyStein Somers-16/+15
2021-02-23BTree: no longer define impossible castsStein Somers-8/+10
2021-02-23BTree: split off reusable components from range_searchStein Somers-118/+227
2021-02-23Add more links between hash and btree collectionsJoshua Nelson-3/+4
- Link from `core::hash` to `HashMap` and `HashSet` - Link from HashMap and HashSet to the module-level documentation on when to use the collection - Link from several collections to Wikipedia articles on the general concept
2021-02-23Auto merge of #82430 - Dylan-DPC:rollup-nu4kfyc, r=Dylan-DPCbors-1/+1
Rollup of 12 pull requests Successful merges: - #79423 (Enable smart punctuation) - #81154 (Improve design of `assert_len`) - #81235 (Improve suggestion for tuple struct pattern matching errors.) - #81769 (Suggest `return`ing tail expressions that match return type) - #81837 (Slight perf improvement on char::to_ascii_lowercase) - #81969 (Avoid `cfg_if` in `std::os`) - #81984 (Make WASI's `hard_link` behavior match other platforms.) - #82091 (use PlaceRef abstractions more consistently) - #82128 (add diagnostic items for OsString/PathBuf/Owned as well as to_vec on slice) - #82166 (add s390x-unknown-linux-musl target) - #82234 (Remove query parameters when skipping search results) - #82255 (Make `treat_err_as_bug` Option<NonZeroUsize>) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-02-23Rollup merge of #81154 - dylni:improve-design-of-assert-len, r=KodrAusDylan DPC-1/+1
Improve design of `assert_len` It was discussed in the [tracking issue](https://github.com/rust-lang/rust/issues/76393#issuecomment-761765448) that `assert_len`'s name and usage are confusing. This PR improves them based on a suggestion by ``@scottmcm`` in that issue. I also improved the documentation to make it clearer when you might want to use this method. Old example: ```rust let range = range.assert_len(slice.len()); ``` New example: ```rust let range = range.ensure_subset_of(..slice.len()); ``` Fixes #81157
2021-02-23Auto merge of #81937 - ssomers:btree_drainy_refactor_9b, r=Mark-Simulacrumbors-98/+67
BTree: move more shared iterator code into navigate.rs The functions in navigate.rs only exist to support iterators, and these look easier on my eyes if there is a shared `struct` with the recurring pair of handles. r? `@Mark-Simulacrum`
2021-02-22Auto merge of #81362 - ssomers:btree_drainy_refactor_8, r=Mark-Simulacrumbors-146/+176
BTreeMap: gather and decompose reusable tree fixing functions This is kind of pushing it as a standalone refactor, probably only useful for #81075 (or similar). r? `@Mark-Simulacrum`
2021-02-21BTreeMap: correct tests for alternative choices of BStein Somers-5/+6
2021-02-21Improve sift_down performance in BinaryHeapHan Mertens-2/+2
Because child > 0, the two statements are equivalent, but using saturating_sub and <= yields in faster code. This is most notable in the binary_heap::bench_into_sorted_vec benchmark, which shows a speedup of 1.26x, which uses sift_down_range internally. The speedup of pop (that uses sift_down_to_bottom internally) is much less significant as the sifting method is not called in a loop.
2021-02-21Rollup merge of #81706 - SkiFire13:document-binaryheap-unsafe, r=Mark-SimulacrumYuki Okushi-49/+117
Document BinaryHeap unsafe functions `BinaryHeap` contains some private safe functions but that are actually unsafe to call. This PR marks them `unsafe` and documents all the `unsafe` function calls inside them. While doing this I might also have found a bug: some "SAFETY" comments in `sift_down_range` and `sift_down_to_bottom` are valid only if you assume that `child` doesn't overflow. However it may overflow if `end > isize::MAX` which can be true for ZSTs (but I think only for them). I guess the easiest fix would be to skip any sifting if `mem::size_of::<T> == 0`. Probably conflicts with #81127 but solving the eventual merge conflict should be pretty easy.
2021-02-21Rollup merge of #81300 - ssomers:btree_cleanup_leak_tests, r=Mark-SimulacrumYuki Okushi-217/+337
BTree: share panicky test code & test panic during clear, clone Bases almost all tests of panic on the same, richer definition, and extends it to cloning to test panic during clone. r? ```@Mark-Simulacrum```
2021-02-20Add FIXME for safety comments that are invalid when T is a ZSTGiacomo Stevanato-0/+4
2021-02-20Document BinaryHeap unsafe functionsGiacomo Stevanato-49/+113
2021-02-20alloc: Added `as_slice` method to `BinaryHeap` collectionVlad Frolov-0/+23
2021-02-15Rollup merge of #82060 - taiki-e:typo, r=m-ou-seJonas Schievink-12/+12
Fix typos in BTreeSet::{first, last} docs map -> set
2021-02-15BTree: move more shared iterator code into navigate.rsStein Somers-98/+67
2021-02-14Rollup merge of #81919 - ssomers:btree_cleanup_comments, r=Mark-SimulacrumDylan DPC-4/+5
BTreeMap: fix internal comments Salvaged from #81372 r? `@Mark-Simulacrum`
2021-02-14Auto merge of #81956 - ssomers:btree_post_75200, r=Mark-Simulacrumbors-19/+7
BTree: remove outdated traces of coercions The introduction of `marker::ValMut` (#75200) meant iterators no longer see mutable keys but their code still pretends it does. And settle on the majority style `Some(unsafe {…})` over `unsafe { Some(…) }`. r? `@Mark-Simulacrum`
2021-02-13Fix typos in BTreeSet::{first, last} docsTaiki Endo-12/+12
2021-02-12Rename `Range::ensure_subset_of` to `slice::range`dylni-1/+1
2021-02-12Fix possible soundness issue in `ensure_subset_of`dylni-1/+1
2021-02-12Improve design of `assert_len`dylni-1/+1
2021-02-12Use raw ref macros as in #80886Stein Somers-3/+3
2021-02-12Initialize BTree nodes directly in the heapJosh Stone-18/+30
2021-02-10BTree: remove outdated traces of coercionsStein Somers-19/+7
2021-02-09BTreeMap: disentangle Drop implementation from IntoIterStein Somers-65/+106
2021-02-09BTreeMap: gather and decompose reusable tree fixing functionsStein Somers-146/+176
2021-02-09BTreeMap: fix internal commentsStein Somers-4/+5
2021-02-09BTreeMap: share panicky test code & test panic during clear, cloneStein Somers-183/+303
2021-02-09BTreeMap/BTreeSet: separate off code supporting testsStein Somers-34/+34
2021-02-08Auto merge of #81361 - ssomers:btree_drainy_refactor_7, r=Mark-Simulacrumbors-42/+67
BTreeMap: lightly refactor the split_off implementation r? `@Mark-Simulacrum`
2021-02-08Auto merge of #79245 - ssomers:btree_curb_ord_bound, r=dtolnaybors-20/+22
BTree: remove Ord bound where it is absent elsewhere Some btree methods don't really need an Ord bound and don't have one, while some methods that more obviously don't need it, do have one. An example of the former is `iter`, even though it explicitly exposes the work of the Ord implementation (["sorted by key"](https://doc.rust-lang.org/std/collections/struct.BTreeMap.html#method.iter) - but I'm not suggesting it should have the Ord bound). An example of the latter is `new`, which doesn't involve any keys whatsoever.
2021-02-07Rollup merge of #81526 - ojeda:btree-use-unwrap_unchecked, r=scottmcmGuillaume Gomez-31/+12
btree: use Option's unwrap_unchecked() Now that https://github.com/rust-lang/rust/issues/81383 is available, start using it.
2021-02-06Rollup merge of #81434 - ssomers:btree_drain_filter_doc_update, r=dtolnayJonas Schievink-16/+18
BTree: fix documentation of unstable public members As rightfully requested in #62924 & #70530. r? `@Mark-Simulacrum`
2021-02-06BTreeMap: remove Ord bound where it is absent elsewhereStein Somers-20/+22
2021-02-06BTreeMap: fix documentation of unstable public membersStein Somers-16/+18
2021-02-06Rollup merge of #81610 - ssomers:btree_emphasize_ord_bound, r=dtolnayMara Bos-54/+191
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-02Rollup merge of #81588 - xfix:delete-doc-alias, r=Mark-SimulacrumJack Huey-0/+2
Add doc aliases for "delete" This patch adds doc aliases for "delete". The added aliases are supposed to reference usages `delete` in other programming languages. - `HashMap::remove`, `BTreeMap::remove` -> `Map#delete` and `delete` keyword in JavaScript. - `HashSet::remove`, `BTreeSet::remove` -> `Set#delete` in JavaScript. - `mem::drop` -> `delete` keyword in C++. - `fs::remove_file`, `fs::remove_dir`, `fs::remove_dir_all`-> `File#delete` in Java, `File#delete` and `Dir#delete` in Ruby. Before this change, searching for "delete" in documentation returned no results.
2021-02-02BTreeMap: make Ord bound explicit, compile-test its absenceStein Somers-54/+191
2021-01-31Add doc aliases for "delete"Konrad Borowski-0/+2
This patch adds doc aliases for "delete". The added aliases are supposed to reference usages `delete` in other programming languages. - `HashMap::remove`, `BTreeMap::remove` -> `Map#delete` and `delete` keyword in JavaScript. - `HashSet::remove`, `BTreeSet::remove` -> `Set#delete` in JavaScript. - `mem::drop` -> `delete` keyword in C++. - `fs::remove_file`, `fs::remove_dir`, `fs::remove_dir_all` -> `File#delete` in Java, `File#delete` and `Dir#delete` in Ruby. Before this change, searching for "delete" in documentation returned no results.
2021-01-30Rollup merge of #80886 - RalfJung:stable-raw-ref-macros, r=m-ou-seYuki Okushi-2/+2
Stabilize raw ref macros This stabilizes `raw_ref_macros` (https://github.com/rust-lang/rust/issues/73394), which is possible now that https://github.com/rust-lang/rust/issues/74355 is fixed. However, as I already said in https://github.com/rust-lang/rust/issues/73394#issuecomment-751342185, I am not particularly happy with the current names of the macros. So I propose we also change them, which means I am proposing to stabilize the following in `core::ptr`: ```rust pub macro const_addr_of($e:expr) { &raw const $e } pub macro mut_addr_of($e:expr) { &raw mut $e } ``` The macro name change means we need another round of FCP. Cc `````@rust-lang/libs````` Fixes #73394
2021-01-29btree: use Option's unwrap_unchecked()Miguel Ojeda-31/+12
Now that https://github.com/rust-lang/rust/issues/81383 is available, start using it. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-01-29rename raw_const/mut -> const/mut_addr_of, and stabilize themRalf Jung-2/+2
2021-01-29Auto merge of #81073 - ssomers:btree_owned_root_vs_dying, r=Mark-Simulacrumbors-32/+73
BTreeMap: prevent tree from ever being owned by non-root node This introduces a new marker type, `Dying`, which is used to note trees which are in the process of deallocation. On such trees, some fields may be in an inconsistent state as we are deallocating the tree. Unfortunately, there's not a great way to express conditional unsafety, so the methods for traversal can cause UB if not invoked correctly, but not marked as such. This is not a regression from the previous state, but rather isolates the destructive methods to solely being called on the dying state.
2021-01-27Auto merge of #81335 - thomwiggers:no-panic-shrink-to, r=Mark-Simulacrumbors-8/+5
Trying to shrink_to greater than capacity should be no-op Per the discussion in https://github.com/rust-lang/rust/issues/56431, `shrink_to` shouldn't panic if you try to make a vector shrink to a capacity greater than its current capacity.
2021-01-27Rollup merge of #81191 - ssomers:btree_more_order_chaos, r=Mark-SimulacrumYuki Okushi-1/+87
BTreeMap: test all borrowing interfaces and test more chaotic order behavior Inspired by #81169, test what happens if you mess up order of the type with which you search (as opposed to the key type). r? `@Mark-Simulacrum`
2021-01-26BTreeMap: stop tree from being owned by non-root nodeStein Somers-32/+73
2021-01-26shrink_to shouldn't panic on len greater than capacityThom Wiggers-8/+5