[−][src]Struct min_max_heap::MinMaxHeap
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_max(&self) -> Option<&T>
[src]
Gets a reference to the maximum element, if any.
O(1).
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]
fn clone(&self) -> MinMaxHeap<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T: Ord> From<Vec<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?
fn into_iter(self) -> Self::IntoIter
[src]
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?
fn into_iter(self) -> Self::IntoIter
[src]
impl<T: Ord> Extend<T> for MinMaxHeap<T>
[src]
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
[src]
impl<'a, T: Ord + Clone + 'a> Extend<&'a T> for MinMaxHeap<T>
[src]
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)
[src]
impl<T> Default for MinMaxHeap<T>
[src]
impl<T: Debug> Debug for MinMaxHeap<T>
[src]
impl<T: Ord> FromIterator<T> for MinMaxHeap<T>
[src]
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
Auto Trait Implementations
impl<T> Send for MinMaxHeap<T> where
T: Send,
T: Send,
impl<T> Sync for MinMaxHeap<T> where
T: Sync,
T: Sync,
Blanket Implementations
impl<T> From for T
[src]
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
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?
fn into_iter(self) -> I
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,