about summary refs log tree commit diff
path: root/library/alloc/src/collections/binary_heap
AgeCommit message (Collapse)AuthorLines
2025-03-12Rollup merge of #138161 - HeroicKatora:heap-peek-mut-refresh, r=dtolnayMatthias Krüger-4/+78
Add PeekMut::refresh I'm not sure if this should go through ACP or not. BinaryHeap is not the most critical data structure in the standard library and it would be understandable if maintainer throughput is thus too limited to accept this PR without a proper design phase that ensures the required understanding of consequence over a longer time period. This aims to improve the useability of heaps for priority-based work queues. In certain scenarios, modifications on the most relevant or critical items are performed until a condition that determines the work items have been sufficiently addressed. For instance the criticality could be a deadline that is relaxed whenever some part of a work item is completed. Such a loop will repeatedly access the most critical item and put it back in a sorted position when it is complete. Crucially, due to the ordering invariant we know that all necessary work was performed when the completed item remains the most critical. Getting this information from the heap position avoids a (potentially more costly) check on the item state itself. A customized `drop` with boolean result would avoid up to two more comparisons performed in both the last no-op refresh and Drop code but this occurs once in each execution of the above scenario whereas refresh occurs any number of times. Also note that the comparison overhead of Drop is only taken if the element is mutably inspected to determine the end condition, i.e. not when refresh itself is the break condition.
2025-03-11Add PeekMut::refreshAurelia Molzer-4/+78
This improves the useability of heaps for priority-based work queues. In certain scenarios, modifications on the most relevant or critical items are performed until a condition that determines the work items have been sufficiently addressed. The loop will repeatedly access the most critical item and put it back in a sorted position when it is complete. Crucially, due to the ordering invariant we know that all work was performed when the completed item remains the most critical. Getting this information from the heap position avoids a (potentially more costly) check on the item state itself. A customized `drop` with boolean result would avoid up to two more comparisons performed in both the last no-op refresh and Drop code but this occurs once in each execution of the above scenario whereas refresh occurs any number of times. Also note that the comparison overhead of Drop is only taken if the element is mutably inspected to determine the end condition, i.e. not when refresh itself is the break condition.
2025-03-07Fully test the alloc crate through alloctestsbjorn3-1/+4
For the tests that make use of internal implementation details, we include the module to test using #[path] in alloctests now.
2024-12-21Less unwrap() in documentationKornel-2/+1
2024-12-04Move some alloc tests to the alloctests cratebjorn3-583/+0
Unit tests directly inside of standard library crates require a very fragile way of building that is hard to reproduce outside of bootstrap.
2024-11-30get rid of a bunch of unnecessary rustc_const_unstableRalf Jung-1/+0
2024-11-28Also use zero when referencing to capacity or lengthtimvisee-2/+2
2024-10-25library: consistently use American spelling for 'behavior'Ralf Jung-2/+2
2024-10-03Avoid emptiness check in `PeekMut::pop`EFanZh-1/+4
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-2/+2
2024-09-18[Clippy] Swap `manual_retain` to use diagnostic items instead of pathsGnomedDev-0/+1
2024-09-03replace placeholder versionBoxy-1/+1
2024-08-07Rollup merge of #128261 - clarfonthey:iter-default, r=dtolnayMatthias Krüger-0/+14
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-07-29Reformat `use` declarations.Nicholas Nethercote-4/+5
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-27Okay, I guess I have to give these a different feature nameltdk-1/+1
2024-07-27impl Default for collection iterators that don't already have itltdk-0/+14
2024-07-26Fix doc nitsJohn Arundel-1/+2
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-24Rollup merge of #125962 - Coekjan:const-binary-heap, r=AmanieuMatthias Krüger-1/+1
Update tracking issue for `const_binary_heap_new_in` This PR updates the tracking issue of `const_binary_heap_new_in` feature: - Old issue: #112353 - New issue: #125961
2024-06-11replace version placeholderPietro Albini-5/+2
2024-06-07Rollup merge of #124012 - slanterns:as_slice_stabilize, r=BurntSushiMatthias Krüger-2/+1
Stabilize `binary_heap_as_slice` This PR stabilizes `binary_heap_as_slice`: ```rust // std::collections::BinaryHeap impl BinaryHeap<T> { pub fn as_slice(&self) -> &[T] } ``` <br> Tracking issue: https://github.com/rust-lang/rust/issues/83659. Implementation PR: https://github.com/rust-lang/rust/pull/82331. FCPs already completed in the tracking issue. Closes https://github.com/rust-lang/rust/issues/83659. r? libs-api
2024-06-04update tracking issue for `const_binary_heap_new_in`coekjan-1/+1
2024-06-01stablize `const_binary_heap_constructor` & create an unstable feature ↵coekjan-2/+5
`const_binary_heap_new_in` for `BinaryHeap::new_in`
2024-04-24fix typo in binary_heap docsThomas Lindae-1/+1
2024-04-16Stabilize `BinaryHeap::as_slice`Slanterns-2/+1
2024-03-08Document overrides of `clone_from()`Noa-0/+6
Specifically, when an override doesn't just forward to an inner type, document the behavior and that it's preferred over simply assigning a clone of source. Also, change instances where the second parameter is "other" to "source".
2024-02-22Add `rustc_confusables` annotations to some stdlib APIsEsteban Küber-0/+2
Help with common API confusion, like asking for `push` when the data structure really has `append`. ``` error[E0599]: no method named `size` found for struct `Vec<{integer}>` in the current scope --> $DIR/rustc_confusables_std_cases.rs:17:7 | LL | x.size(); | ^^^^ | help: you might have meant to use `len` | LL | x.len(); | ~~~ help: there is a method with a similar name | LL | x.resize(); | ~~~~~~ ``` #59450
2024-02-15Replace `NonZero::<_>::new` with `NonZero::new`.Markus Reiter-3/+3
2024-02-15Use generic `NonZero` internally.Markus Reiter-5/+5
2023-12-10remove redundant importssurechen-2/+0
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-11-28Auto merge of #110353 - the8472:in-place-flatten-chunks, r=cuviperbors-2/+9
Expand in-place iteration specialization to Flatten, FlatMap and ArrayChunks This enables the following cases to collect in-place: ```rust let v = vec![[0u8; 4]; 1024] let v: Vec<_> = v.into_iter().flatten().collect(); let v: Vec<Option<NonZeroUsize>> = vec![NonZeroUsize::new(0); 1024]; let v: Vec<_> = v.into_iter().flatten().collect(); let v = vec![u8; 4096]; let v: Vec<_> = v.into_iter().array_chunks::<4>().collect(); ``` Especially the nicheful-option-flattening should be useful in real code.
2023-10-28mark constructor of `BinaryHeap` as const fncoekjan-2/+4
2023-09-03Expand in-place iteration specialization to Flatten, FlatMap and ArrayChunksThe 8472-2/+9
2023-06-13Auto merge of #112314 - ferrocene:pa-core-alloc-abort, r=bjorn3bors-0/+3
Ignore `core`, `alloc` and `test` tests that require unwinding on `-C panic=abort` Some of the tests for `core` and `alloc` require unwinding through their use of `catch_unwind`. These tests fail when testing using `-C panic=abort` (in my case through a target without unwinding support, and `-Z panic-abort-tests`), while they should be ignored as they don't indicate a failure. This PR marks all of these tests with this attribute: ```rust #[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")] ``` I'm not aware of a way to test this on rust-lang/rust's CI, as we don't test any target with `-C panic=abort`, but I tested this locally on a Ferrocene target and it does indeed make the test suite pass.
2023-06-13ignore core, alloc and test tests that require unwinding on panic=abortPietro Albini-0/+3
2023-06-11Impl allocator function for iteratorsyanchith-0/+32
2023-06-11Remove explicit lifetimesyanchith-20/+20
2023-06-09Don't explicitly name Globalyanchith-1/+1
2023-06-09Pass tidy againyanchith-5/+1
2023-06-09Add allocator functionyanchith-0/+7
2023-06-09Reallocatorize after mergeyanchith-12/+16
2023-06-09Merge branch 'master' into binary-heap-tayanchith-26/+1944
2023-04-28replace version placeholdersPietro Albini-2/+2
2023-04-12remove some unneeded importsKaDiWa-3/+1
2023-04-03Auto merge of #108448 - ishitatsuyuki:binary-heap, r=Mark-Simulacrumbors-51/+19
binary_heap: Optimize Extend implementation. This PR makes the `Extend` implementation for `BinaryHeap` no longer rely on specialization, so that it always use the bulk rebuild optimization that was previously only available for the `Vec` specialization.
2023-03-28Stabilize `binary_heap_retain`Amanieu d'Antras-2/+1
FCP finished in tracking issue: #71503
2023-02-28rewrite iterator `Default` tests as doctestsThe 8472-0/+7
2023-02-28Implement Default for some alloc/core iteratorsThe 8472-0/+7
This way one can `mem::take()` them out of structs or #[derive(Default)] on structs containing them. These changes will be insta-stable.
2023-02-25binary_heap: Unify Extend implementation.Tatsuyuki Ishi-34/+2
Previously the bulk rebuild specialization was only available with Vec, and for general iterators Extend only provided pre-allocation through reserve(). By using a drop guard, we can safely bulk rebuild even if the iterator may panic. This allows benefiting from the bulk rebuild optimization without collecting iterator elements into a Vec beforehand, which would nullify any performance gains from bulk rebuild.
2023-02-25binary_heap: Make RebuildOnDrop a common helper.Tatsuyuki Ishi-17/+17
This helper was written for retain() but will also be useful for extend().
2023-01-15Rebuild BinaryHeap on unwind from retainDavid Tolnay-7/+21