about summary refs log tree commit diff
path: root/library/alloc/src/collections/binary_heap.rs
AgeCommit message (Collapse)AuthorLines
2021-10-11Rollup merge of #89726 - jkugelman:must-use-alloc-constructors, r=joshtriplettGuillaume Gomez-0/+2
Add #[must_use] to alloc constructors Added `#[must_use]`. to the various forms of `new`, `pin`, and `with_capacity` in the `alloc` crate. No extra explanations given as I couldn't think of anything useful to add. I figure this deserves extra scrutiny compared to the other PRs I've done so far. In particular: * The 4 `pin`/`pin_in` methods I touched. Are there legitimate use cases for pinning and not using the result? Pinning's a difficult concept I'm not very comfortable with. * `Box`'s constructors. Do people ever create boxes just for the side effects... allocating or zeroing out memory? Parent issue: #89692 r? ``@joshtriplett``
2021-10-10Add #[must_use] to conversions that move selfJohn Kugelman-0/+2
2021-10-10Add #[must_use] to alloc constructorsJohn Kugelman-0/+2
2021-09-25Rollup merge of #89216 - r00ster91:bigo, r=dtolnayManish Goregaokar-4/+4
Consistent big O notation This makes the big O time complexity notation in places with markdown support more consistent. Inspired by #89210
2021-09-24consistent big O notationr00ster91-4/+4
2021-09-16Add IntoIterator intra doc link to various collectionsest31-1/+2
2021-09-16Add intra-doc-links to BinaryHeap rustdocest31-3/+7
2021-08-22Fix typos “an”→“a” and a few different ones that appeared in the ↵Frank Steffahn-1/+1
same search
2021-08-08Auto merge of #86879 - YohDeadfall:stabilize-vec-shrink-to, r=dtolnaybors-2/+1
Stabilize Vec<T>::shrink_to This PR stabilizes `shrink_to` feature and closes the corresponding issue. The second point was addressed already, and no `panic!` should occur. Closes #56431.
2021-08-08Bump shrink_to stabilization to Rust 1.56David Tolnay-1/+1
2021-07-24Auto merge of #84111 - bstrie:hashfrom, r=joshtriplettbors-0/+24
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-24Update std_collections_from_array stability versionbstrie-1/+1
2021-07-06Stabilize Vec<T>::shrink_toYoh Deadfall-2/+1
2021-06-30impl From<[(K, V); N]> for std::collectionsbstrie-0/+24
2021-06-30Remove "length" doc aliasesAmanieu d'Antras-1/+0
2021-05-16mark internal inplace_iteration traits as hiddenThe8472-0/+2
2021-04-22Improve BinaryHeap::retain.Mara Bos-32/+53
It now doesn't fully rebuild the heap, but only the parts that are necessary.
2021-03-30Rollup merge of #82331 - frol:feat/std-binary-heap-as-slice, r=AmanieuDylan DPC-0/+21
alloc: Added `as_slice` method to `BinaryHeap` collection I initially asked about whether it is useful addition on https://internals.rust-lang.org/t/should-i-add-as-slice-method-to-binaryheap/13816, and it seems there were no objections, so went ahead with this PR. > There is [`BinaryHeap::into_vec`](https://doc.rust-lang.org/std/collections/struct.BinaryHeap.html#method.into_vec), but it consumes the value. I wonder if there is API design limitation that should be taken into account. Implementation-wise, the inner buffer is just a Vec, so it is trivial to expose as_slice from it. Please, guide me through if I need to add tests or something else. UPD: Tracking issue #83659
2021-03-29Updated the tracking issue #Vlad Frolov-1/+1
2021-03-13provide a more realistic example for BinaryHeap::as_sliceVlad Frolov-5/+3
2021-03-09Rollup merge of #81127 - hanmertens:binary_heap_sift_down_perf, r=dtolnayMara Bos-2/+2
Improve sift_down performance in BinaryHeap Replacing `child < end - 1` with `child <= end.saturating_sub(2)` in `BinaryHeap::sift_down_range` (surprisingly) results in a significant speedup of `BinaryHeap::into_sorted_vec`. The same substitution can be done for `BinaryHeap::sift_down_to_bottom`, which causes a slight but probably statistically insignificant speedup for `BinaryHeap::pop`. It's interesting that benchmarks aside from `bench_into_sorted_vec` are barely affected, even those that do use `sift_down_*` methods internally. | Benchmark | Before (ns/iter) | After (ns/iter) | Speedup | |--------------------------|------------------|-----------------|---------| | bench_find_smallest_1000<sup>1</sup> | 392,617 | 385,200 | 1.02 | | bench_from_vec<sup>1</sup> | 506,016 | 504,444 | 1.00 | | bench_into_sorted_vec<sup>1</sup> | 476,869 | 384,458 | 1.24 | | bench_peek_mut_deref_mut<sup>3</sup> | 518,753 | 519,792 | 1.00 | | bench_pop<sup>2</sup> | 446,718 | 444,409 | 1.01 | | bench_push<sup>3</sup> | 772,481 | 770,208 | 1.00 | <sup>1</sup>: internally calls `sift_down_range` <sup>2</sup>: internally calls `sift_down_to_bottom` <sup>3</sup>: should not be affected
2021-03-01Add diagnostic itemsCameron Steffen-0/+1
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-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-01-26shrink_to shouldn't panic on len greater than capacityThom Wiggers-2/+1
2021-01-16Rollup merge of #80681 - ChrisJefferson:logic-error-doc, r=m-ou-seMara Bos-1/+4
Clarify what the effects of a 'logic error' are This clarifies what a 'logic error' is (which is a term used to describe what happens if you put things in a hash table or btree and then use something like a refcell to break the internal ordering). This tries to be as vague as possible, as we don't really want to promise what happens, except "bad things, but not UB". This was discussed in #80657
2021-01-16Clarify what the effects of a 'logic error' areChris Jefferson-1/+4
2021-01-15Change rebuild heuristic in BinaryHeap::appendHan Mertens-2/+8
See #77433 for why the new heuristic was chosen. Fixes #77433
2020-12-28Add "length" as doc alias to len methodsKonrad Borowski-0/+1
2020-11-09Added SAFETY comment as requestGiacomo Stevanato-0/+4
2020-11-07Remove useless bound checks from into_sorted_vecGiacomo Stevanato-1/+4
2020-11-07Remove useless branches from sift_down_range loopGiacomo Stevanato-6/+6
2020-11-07Remove branches from sift_down_to_bottom loopGiacomo Stevanato-6/+5
2020-10-31fix aliasing issue in binary_heapRalf Jung-2/+3
2020-09-23Use Self in allocAlexis Bourget-2/+2
2020-09-21Auto merge of #75974 - SkiFire13:peekmut-opt-sift, r=LukasKalbertodtbors-2/+4
Avoid useless sift_down when std::collections::binary_heap::PeekMut is never mutably dereferenced If `deref_mut` is never called then it's not possible for the element to be mutated without internal mutability, meaning there's no need to call `sift_down`. This could be a little improvement in cases where you want to mutate the biggest element of the heap only if it satisfies a certain predicate that needs only read access to the element.
2020-09-20Rollup merge of #76875 - denisvasilik:intra-doc-links-alloc-binary-heap, ↵Ralf Jung-20/+14
r=jyn514 Move to intra-doc links in library/alloc/src/collections/binary_heap.rs Helps with #75080. @rustbot modify labels: T-doc, A-intra-doc-links
2020-09-20Fix time complexity in BinaryHeap::peek_mut docsGiacomo Stevanato-1/+2
2020-09-20Set sift=true only when PeekMut yields a mutable referenceGiacomo Stevanato-1/+2
2020-09-19Use `T::BITS` instead of `size_of::<T> * 8`.Mara Bos-2/+2
2020-09-18Update library/alloc/src/collections/binary_heap.rsDenis Vasilik-1/+1
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-09-18Update library/alloc/src/collections/binary_heap.rsDenis Vasilik-1/+1
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-09-18Update library/alloc/src/collections/binary_heap.rsDenis Vasilik-1/+1
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-09-18Update library/alloc/src/collections/binary_heap.rsDenis Vasilik-1/+1
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-09-18Use intra-doc linksDenis Vasilik-16/+10
2020-09-09Add documentation for `impl<T> From<BinaryHeap<T>> for Vec<T>`Michael Howell-0/+4
2020-09-03generalize in-place collect to types of same size and alignmentThe8472-2/+4
2020-09-03pacify tidyThe8472-3/+3