pub struct SliceHeap<'a, T: Ord + Copy> { /* private fields */ }Expand description
A fixed-size heap data structure that operates in place on non-empty mutable slices.
The heap size never changes after creation, and only supports updating the maximum element.
Implementations§
Source§impl<'a, T: Ord + Copy> SliceHeap<'a, T>
impl<'a, T: Ord + Copy> SliceHeap<'a, T>
Sourcepub fn new(data: &'a mut [T]) -> Result<Self, EmptySlice>
pub fn new(data: &'a mut [T]) -> Result<Self, EmptySlice>
Creates a new SliceHeap from a mutable slice.
The slice is assumed to be unordered initially and will be heapified.
§Errors
Returns EmptySlice if the input slice is empty.
Sourcepub fn new_unchecked(data: &'a mut [T]) -> Result<Self, EmptySlice>
pub fn new_unchecked(data: &'a mut [T]) -> Result<Self, EmptySlice>
Creates a new SliceHeap from a mutable slice without heapifying.
Use this if you know the slice is already in heap order.
§Errors
Returns EmptySlice if the input slice is empty.
Sourcepub fn peek(&self) -> Option<&T>
pub fn peek(&self) -> Option<&T>
Returns a reference to the greatest element in the heap, or None if empty.
Sourcepub fn update_root<F>(&mut self, update_fn: F)
pub fn update_root<F>(&mut self, update_fn: F)
Updates the root element in place and restores the heap property. This allows direct mutation of the maximum element.
Since the heap cannot be empty (enforced by construction), this operation always succeeds.
Auto Trait Implementations§
impl<'a, T> Freeze for SliceHeap<'a, T>
impl<'a, T> RefUnwindSafe for SliceHeap<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for SliceHeap<'a, T>where
T: Send,
impl<'a, T> Sync for SliceHeap<'a, T>where
T: Sync,
impl<'a, T> Unpin for SliceHeap<'a, T>
impl<'a, T> UnsafeUnpin for SliceHeap<'a, T>
impl<'a, T> !UnwindSafe for SliceHeap<'a, T>
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more