pub struct LeonardoHeap<T> { /* private fields */ }
Implementations§
Source§impl<T: Ord + Debug> LeonardoHeap<T>
impl<T: Ord + Debug> LeonardoHeap<T>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new LeonardoHeap<T>
with space allocated for at least
capacity
elements.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements for which space has been allocated.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserve at least enough space for additional
elements to be pushed
on to the heap.
Sourcepub fn reserve_exact(&mut self, additional: usize)
pub fn reserve_exact(&mut self, additional: usize)
Reserves the minimum capacity for exactly additional
elements to be
pushed onto the heap.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the underlying storage to free up as much space as possible.
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Removes all elements from the heap that do not match a predicate.
Sourcepub fn sort(&mut self)
pub fn sort(&mut self)
Forces sorting of the entire underlying array. The sorted array is still a valid leonardo heap.
Sourcepub fn push(&mut self, item: T)
pub fn push(&mut self, item: T)
Adds a new element to the heap. The heap will be rebalanced to maintain the string and heap properties.
Elements pushed more than once will not be deduplicated.
Sourcepub fn peek(&self) -> Option<&T>
pub fn peek(&self) -> Option<&T>
Returns a reference to the largest element in the heap without removing it.
Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Removes and returns the largest element in the heap. If the heap is
empty, returns None
.
Sourcepub fn iter(
&mut self,
) -> impl Iterator<Item = &T> + ExactSizeIterator<Item = &T>
pub fn iter( &mut self, ) -> impl Iterator<Item = &T> + ExactSizeIterator<Item = &T>
Returns a sorted iterator over the elements in the heap.
Will lazily sort the top elements of the heap in-place as it is consumed.
Sourcepub fn drain<'a>(
&'a mut self,
) -> impl Iterator<Item = T> + ExactSizeIterator<Item = T> + 'a
pub fn drain<'a>( &'a mut self, ) -> impl Iterator<Item = T> + ExactSizeIterator<Item = T> + 'a
Returns an iterator that removes and returns elements from the top of the heap.