diff options
| author | Aurelia Molzer <5550310+HeroicKatora@users.noreply.github.com> | 2025-03-07 14:38:08 +0100 |
|---|---|---|
| committer | Andreas Molzer <andreas.molzer@gmx.de> | 2025-03-11 15:58:00 +0100 |
| commit | 436959e3f710d3161093bfa183e3c5deceff7ccf (patch) | |
| tree | 8682542159381ef3e21cb7f24c5c0527705917d6 /library/std/src/sys/stdio/unix.rs | |
| parent | 91a0e1604f343730022bc903cbf201d8b0a86a71 (diff) | |
| download | rust-436959e3f710d3161093bfa183e3c5deceff7ccf.tar.gz rust-436959e3f710d3161093bfa183e3c5deceff7ccf.zip | |
Add PeekMut::refresh
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.
Diffstat (limited to 'library/std/src/sys/stdio/unix.rs')
0 files changed, 0 insertions, 0 deletions
