pub struct PeekMut<'a, T: 'a + Ord, const D: usize> { /* private fields */ }
Expand description
Implementations§
Source§impl<'a, T: Ord, const D: usize> PeekMut<'a, T, D>
impl<'a, T: Ord, const D: usize> PeekMut<'a, T, D>
Sourcepub fn refresh(&mut self) -> bool
Available on crate feature unstable
only.
pub fn refresh(&mut self) -> bool
unstable
only.Sifts the current element to its new position.
Afterwards refers to the new element. Returns if the element changed.
§Examples
The condition can be used to upper bound all elements in the heap. When only few elements are affected, the heap’s sort ensures this is faster than a reconstruction from the raw element list and requires no additional allocation.
use dary_heap::BinaryHeap;
let mut heap: BinaryHeap<u32> = (0..128).collect();
let mut peek = heap.peek_mut().unwrap();
loop {
*peek = 99;
if !peek.refresh() {
break;
}
}
// Post condition, this is now an upper bound.
assert!(*peek < 100);
When the element remains the maximum after modification, the peek remains unchanged:
use dary_heap::BinaryHeap;
let mut heap: BinaryHeap<u32> = [1, 2, 3].into();
let mut peek = heap.peek_mut().unwrap();
assert_eq!(*peek, 3);
*peek = 42;
// When we refresh, the peek is updated to the new maximum.
assert!(!peek.refresh(), "42 is even larger than 3");
assert_eq!(*peek, 42);
Trait Implementations§
Auto Trait Implementations§
impl<'a, T, const D: usize> Freeze for PeekMut<'a, T, D>
impl<'a, T, const D: usize> RefUnwindSafe for PeekMut<'a, T, D>where
T: RefUnwindSafe,
impl<'a, T, const D: usize> Send for PeekMut<'a, T, D>where
T: Send,
impl<'a, T, const D: usize> Sync for PeekMut<'a, T, D>where
T: Sync,
impl<'a, T, const D: usize> Unpin for PeekMut<'a, T, D>
impl<'a, T, const D: usize> !UnwindSafe for PeekMut<'a, T, D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more