pub struct BinomialHeap<T: Ord> { /* private fields */ }Expand description
A priority queue based on a binomial heap.
Like BinaryHeap, BionmialHeap is an implementation of a priority queue. Unlike
BinaryHeap, BionmialHeap provides an efficient append method, at the cost of greater
memory usage, slower iteration, and poor cache locality.
§Time Complexity
Implementations§
Source§impl<T: Ord> BinomialHeap<T>
impl<T: Ord> BinomialHeap<T>
Sourcepub fn iter(&self) -> Iter<'_, T> ⓘ
pub fn iter(&self) -> Iter<'_, T> ⓘ
Returns an iterator that yields references to the items in the heap in arbitrary order.
Sourcepub fn peek(&self) -> Option<&T>
pub fn peek(&self) -> Option<&T>
Returns a reference to the greatest item in the heap.
Returns None if the heap is empty.
Sourcepub fn append(&mut self, other: &mut Self)
pub fn append(&mut self, other: &mut Self)
Moves the given heap’s items into the heap, leaving the given heap empty.
This is equivalent to, but likely to be faster than, the following:
heap.extend(heap2.drain());Sourcepub fn push_pop(&mut self, item: T) -> T
pub fn push_pop(&mut self, item: T) -> T
Pushes the given item onto the heap, then removes the greatest item in the heap and returns it.
This method is equivalent to, but likely faster than, the following:
heap.push(item);
let max = heap.pop().unwrap();Sourcepub fn replace(&mut self, item: T) -> Option<T>
pub fn replace(&mut self, item: T) -> Option<T>
Removes the greatest item in the heap, then pushes the given item onto the heap.
Returns the item that was removed, or None if the heap was empty.
This method is equivalent to, but likely faster than, the following:
let max = heap.pop();
heap.push(item);Sourcepub fn drain(&mut self) -> Drain<'_, T> ⓘ
pub fn drain(&mut self) -> Drain<'_, T> ⓘ
Removes all items from the heap and returns an iterator that yields them in arbitrary order.
All items are removed even if the iterator is not exhausted. However, the behavior of
this method is unspecified if the iterator is leaked (e.g. via mem::forget).
Trait Implementations§
Source§impl<T: Clone + Ord> Clone for BinomialHeap<T>
impl<T: Clone + Ord> Clone for BinomialHeap<T>
Source§fn clone(&self) -> BinomialHeap<T>
fn clone(&self) -> BinomialHeap<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Ord> Default for BinomialHeap<T>
impl<T: Ord> Default for BinomialHeap<T>
Source§impl<'a, T: 'a + Ord + Copy> Extend<&'a T> for BinomialHeap<T>
impl<'a, T: 'a + Ord + Copy> Extend<&'a T> for BinomialHeap<T>
Source§fn extend<I: IntoIterator<Item = &'a T>>(&mut self, items: I)
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, items: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<T: Ord> Extend<T> for BinomialHeap<T>
impl<T: Ord> Extend<T> for BinomialHeap<T>
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, items: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, items: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)