[][src]Struct min_max_heap::MinMaxHeap

pub struct MinMaxHeap<T>(_);

A double-ended priority queue.

Most operations are O(log n).

Methods

impl<T> MinMaxHeap<T>[src]

pub fn new() -> Self[src]

Creates a new, empty MinMaxHeap.

O(1).

pub fn with_capacity(len: usize) -> Self[src]

Creates a new, empty MinMaxHeap with space allocated to hold len elements.

O(n).

pub fn len(&self) -> usize[src]

The number of elements in the heap.

O(1).

pub fn is_empty(&self) -> bool[src]

Is the heap empty?

O(1).

impl<T: Ord> MinMaxHeap<T>[src]

pub fn push(&mut self, element: T)[src]

Adds an element to the heap.

Amortized O(log n); worst-case O(n) when the backing vector needs to grow.

pub fn peek_min(&self) -> Option<&T>[src]

Gets a reference to the minimum element, if any.

O(1).

pub fn peek_min_mut(&mut self) -> Option<PeekMinMut<T>>[src]

Returns a mutable reference to the minimum element, if any. Once this reference is dropped, the heap is adjusted if necessary.

Note: If the PeekMinMut value is leaked, the heap may be in an inconsistent state.

O(1) for the peek; O(log n) when the reference is dropped.

pub fn peek_max(&self) -> Option<&T>[src]

Gets a reference to the maximum element, if any.

O(1).

pub fn peek_max_mut(&mut self) -> Option<PeekMaxMut<T>>[src]

Returns a mutable reference to the maximum element, if any. Once this reference is dropped, the heap is adjusted if necessary.

Note: If the PeekMaxMut value is leaked, the heap may be in an inconsistent state.

O(1) for the peek; O(log n) when the reference is dropped.

pub fn pop_min(&mut self) -> Option<T>[src]

Removes the minimum element, if any.

O(log n).

pub fn pop_max(&mut self) -> Option<T>[src]

Removes the maximum element, if any.

O(log n).

pub fn push_pop_min(&mut self, element: T) -> T[src]

Pushes an element, then pops the minimum element.

Unlike a push followed by a pop, this combined operation will not allocate.

O(log n).

pub fn push_pop_max(&mut self, element: T) -> T[src]

Pushes an element, then pops the maximum element in an optimized fashion.

Unlike a push followed by a pop, this combined operation will not allocate.

O(log n).

pub fn replace_min(&mut self, element: T) -> Option<T>[src]

Pops the minimum, then pushes an element in an optimized fashion.

O(log n).

pub fn replace_max(&mut self, element: T) -> Option<T>[src]

Pops the maximum, then pushes an element in an optimized fashion.

O(log n).

pub fn into_vec_asc(self) -> Vec<T>[src]

Returns an ascending (sorted) vector, reusing the heap’s storage.

O(n log n).

pub fn into_vec_desc(self) -> Vec<T>[src]

Returns an descending (sorted) vector, reusing the heap’s storage.

O(n log n).

impl<T> MinMaxHeap<T>[src]

pub fn clear(&mut self)[src]

Drops all items from the heap.

O(n)

pub fn capacity(&self) -> usize[src]

The number of elements the heap can hold without reallocating.

O(1)

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

Reserves the minimum capacity for exactly additional more elements to be inserted in the given MinMaxHeap.

O(n)

Panics

Panics if the new capacity overflows usize.

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

Reserves the minimum capacity for at least additional more elements to be inserted in the given MinMaxHeap.

O(n)

Panics

Panics if the new capacity overflows usize.

pub fn shrink_to_fit(&mut self)[src]

Discards extra capacity.

O(n)

pub fn into_vec(self) -> Vec<T>[src]

Consumes the MinMaxHeap and returns its elements in a vector in arbitrary order.

O(n)

Important traits for Iter<'a, T>
pub fn iter(&self) -> Iter<T>[src]

Returns a borrowing iterator over the min-max-heap’s elements in arbitrary order.

O(1) on creation, and O(1) for each next() operation.

Important traits for Drain<'a, T>
pub fn drain(&mut self) -> Drain<T>[src]

Returns a draining iterator over the min-max-heap’s elements in arbitrary order.

O(1) on creation, and O(1) for each next() operation.

Important traits for DrainAsc<'a, T>
pub fn drain_asc(&mut self) -> DrainAsc<T>[src]

Returns a draining iterator over the min-max-heap’s elements in ascending (min-first) order.

O(1) on creation, and O(log n) for each next() operation.

Important traits for DrainDesc<'a, T>
pub fn drain_desc(&mut self) -> DrainDesc<T>[src]

Returns a draining iterator over the min-max-heap’s elements in descending (max-first) order.

O(1) on creation, and O(log n) for each next() operation.

Trait Implementations

impl<T: Clone> Clone for MinMaxHeap<T>[src]

impl<T: Debug> Debug for MinMaxHeap<T>[src]

impl<T> Default for MinMaxHeap<T>[src]

impl<'de, T> Deserialize<'de> for MinMaxHeap<T> where
    T: Deserialize<'de>, 
[src]

impl<'a, T: Ord + Clone + 'a> Extend<&'a T> for MinMaxHeap<T>[src]

impl<T: Ord> Extend<T> for MinMaxHeap<T>[src]

impl<T: Ord> From<Vec<T>> for MinMaxHeap<T>[src]

impl<T: Ord> FromIterator<T> for MinMaxHeap<T>[src]

impl<'a, T> IntoIterator for &'a MinMaxHeap<T>[src]

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

impl<'a, T> IntoIterator for MinMaxHeap<T>[src]

type Item = T

The type of the elements being iterated over.

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?

impl<T> Serialize for MinMaxHeap<T> where
    T: Serialize
[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for MinMaxHeap<T> where
    T: RefUnwindSafe

impl<T> Send for MinMaxHeap<T> where
    T: Send

impl<T> Sync for MinMaxHeap<T> where
    T: Sync

impl<T> Unpin for MinMaxHeap<T> where
    T: Unpin

impl<T> UnwindSafe for MinMaxHeap<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.