Struct ic_stable_structures::min_heap::MinHeap
source · pub struct MinHeap<T: Storable + PartialOrd, M: Memory>(/* private fields */);
Expand description
An implementation of the binary min heap.
Implementations§
source§impl<T, M> MinHeap<T, M>
impl<T, M> MinHeap<T, M>
sourcepub fn new(memory: M) -> Result<Self, GrowFailed>
pub fn new(memory: M) -> Result<Self, GrowFailed>
Creates a new empty heap in the specified memory, overwriting any data structures the memory might have contained.
Complexity: O(1)
sourcepub fn init(memory: M) -> Result<Self, InitError>
pub fn init(memory: M) -> Result<Self, InitError>
Initializes a heap in the specified memory.
Complexity: O(1)
PRECONDITION: the memory is either empty or contains a valid stable heap.
sourcepub fn push(&mut self, item: &T) -> Result<(), GrowFailed>
pub fn push(&mut self, item: &T) -> Result<(), GrowFailed>
Pushes an item onto the heap.
Complexity: O(log(self.len()))
sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Removes the smallest item from the heap and returns it.
Returns None
if the heap is empty.
Complexity: O(log(self.len()))
sourcepub fn peek(&self) -> Option<T>
pub fn peek(&self) -> Option<T>
Returns the smallest item in the heap.
Returns None
if the heap is empty.
Complexity: O(1)
sourcepub fn iter(&self) -> impl Iterator<Item = T> + '_
pub fn iter(&self) -> impl Iterator<Item = T> + '_
Returns an iterator visiting all values in the underlying vector, in arbitrary order.
sourcepub fn into_memory(self) -> M
pub fn into_memory(self) -> M
Returns the underlying memory instance.
Trait Implementations§
Auto Trait Implementations§
impl<T, M> Freeze for MinHeap<T, M>where
M: Freeze,
impl<T, M> RefUnwindSafe for MinHeap<T, M>where
M: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, M> Send for MinHeap<T, M>
impl<T, M> Sync for MinHeap<T, M>
impl<T, M> Unpin for MinHeap<T, M>
impl<T, M> UnwindSafe for MinHeap<T, M>where
M: UnwindSafe,
T: UnwindSafe,
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