Struct LeonardoHeap

Source
pub struct LeonardoHeap<T> { /* private fields */ }

Implementations§

Source§

impl<T: Ord + Debug> LeonardoHeap<T>

Source

pub fn new() -> Self

Creates a new, empty LeonardoHeap<T>

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new LeonardoHeap<T> with space allocated for at least capacity elements.

Source

pub fn capacity(&self) -> usize

Returns the number of elements for which space has been allocated.

Source

pub fn reserve(&mut self, additional: usize)

Reserve at least enough space for additional elements to be pushed on to the heap.

Source

pub fn reserve_exact(&mut self, additional: usize)

Reserves the minimum capacity for exactly additional elements to be pushed onto the heap.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the underlying storage to free up as much space as possible.

Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&T) -> bool,

Removes all elements from the heap that do not match a predicate.

Source

pub fn clear(&mut self)

Removes all elements from the heap.

Source

pub fn len(&self) -> usize

Returns the number of elements in the heap.

Source

pub fn is_empty(&self) -> bool

Returns true if the heap contains no elements, false otherwise.

Source

pub fn dedup(&mut self)

Removes duplicate elements from the heap, preserving heap order.

Source

pub fn sort(&mut self)

Forces sorting of the entire underlying array. The sorted array is still a valid leonardo heap.

Source

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.

Source

pub fn peek(&self) -> Option<&T>

Returns a reference to the largest element in the heap without removing it.

Source

pub fn pop(&mut self) -> Option<T>

Removes and returns the largest element in the heap. If the heap is empty, returns None.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<T: Debug> Debug for LeonardoHeap<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for LeonardoHeap<T>

§

impl<T> RefUnwindSafe for LeonardoHeap<T>
where T: RefUnwindSafe,

§

impl<T> Send for LeonardoHeap<T>
where T: Send,

§

impl<T> Sync for LeonardoHeap<T>
where T: Sync,

§

impl<T> Unpin for LeonardoHeap<T>
where T: Unpin,

§

impl<T> UnwindSafe for LeonardoHeap<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.