pub struct PopulatedBinaryHeap<T>(/* private fields */);Implementations§
Source§impl<T: Ord> PopulatedBinaryHeap<T>
impl<T: Ord> PopulatedBinaryHeap<T>
Sourcepub fn new(value: T) -> PopulatedBinaryHeap<T>
pub fn new(value: T) -> PopulatedBinaryHeap<T>
Creates a binary heap populated with a single value.
Sourcepub fn with_capacity(capacity: NonZeroUsize, value: T) -> PopulatedBinaryHeap<T>
pub fn with_capacity(capacity: NonZeroUsize, value: T) -> PopulatedBinaryHeap<T>
Creates a binary populated with a single value and the given capacity.
Sourcepub fn into_sorted_vec(self) -> PopulatedVec<T>
pub fn into_sorted_vec(self) -> PopulatedVec<T>
Consumes the PopulatedBinaryHeap and returns a populated vector
in sorted (ascending) order.
Sourcepub fn append(&mut self, other: &mut BinaryHeap<T>)
pub fn append(&mut self, other: &mut BinaryHeap<T>)
Moves all the elements of other into self, leaving other empty.
Sourcepub fn retain(self, predicate: impl FnMut(&T) -> bool) -> BinaryHeap<T>
pub fn retain(self, predicate: impl FnMut(&T) -> bool) -> BinaryHeap<T>
Retains only the elements specified by the predicate.
In other words, remove all elements e for which f(&e) returns false. The elements are visited in unsorted (and unspecified) order.
Note that the binary heap is not guaranteed to be populated after calling this method.
use populated::PopulatedBinaryHeap;
use std::num::NonZeroUsize;
let mut binary_heap = PopulatedBinaryHeap::with_capacity(NonZeroUsize::new(5).unwrap(), 1);
binary_heap.push(2);
binary_heap.push(3);
let binary_heap = binary_heap.retain(|&x| x > 2);
assert_eq!(binary_heap.len(), 1);Sourcepub fn pop(self) -> (T, BinaryHeap<T>)
pub fn pop(self) -> (T, BinaryHeap<T>)
Removes the greatest item from the binary heap and returns it along with the remaining binary heap. Note that the returned binary heap is not guaranteed to be populated.
use populated::PopulatedBinaryHeap;
use std::num::NonZeroUsize;
let mut binary_heap = PopulatedBinaryHeap::with_capacity(NonZeroUsize::new(5).unwrap(), 1);
binary_heap.push(2);
binary_heap.push(3);
let (item, binary_heap) = binary_heap.pop();
assert_eq!(item, 3);
assert_eq!(binary_heap.len(), 2);Source§impl<T> PopulatedBinaryHeap<T>
impl<T> PopulatedBinaryHeap<T>
Sourcepub fn peek(&self) -> &T
pub fn peek(&self) -> &T
Returns the greatest item in the populated binary heap.
use populated::PopulatedBinaryHeap;
let mut binary_heap = PopulatedBinaryHeap::new(1);
binary_heap.push(2);
binary_heap.push(3);
assert_eq!(binary_heap.peek(), &3);Sourcepub fn capacity(&self) -> NonZeroUsize
pub fn capacity(&self) -> NonZeroUsize
Returns the number of elements the binary heap can hold without reallocating.
use populated::PopulatedBinaryHeap;
use std::num::NonZeroUsize;
let binary_heap = PopulatedBinaryHeap::with_capacity(NonZeroUsize::new(10).unwrap(), 1);
assert_eq!(binary_heap.capacity(), NonZeroUsize::new(10).unwrap());Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Discards as much additional capacity as possible. The capacity will never be less than the length.
Sourcepub fn into_vec(self) -> PopulatedVec<T>
pub fn into_vec(self) -> PopulatedVec<T>
Consumes the PopulatedBinaryHeap and returns a populated vector with elements in arbitrary order.
use populated::PopulatedBinaryHeap;
let mut binary_heap = PopulatedBinaryHeap::new(1);
binary_heap.push(2);
binary_heap.push(3);
let vec = binary_heap.into_vec();
assert_eq!(vec.len().get(), 3);Sourcepub fn len(&self) -> NonZeroUsize
pub fn len(&self) -> NonZeroUsize
Returns the number of elements in the binary heap. Guaranteed to be non-zero.
use populated::PopulatedBinaryHeap;
let mut binary_heap = PopulatedBinaryHeap::new(1);
binary_heap.push(2);
binary_heap.push(3);
assert_eq!(binary_heap.len().get(), 3);Sourcepub fn clear(self) -> BinaryHeap<T>
pub fn clear(self) -> BinaryHeap<T>
Drops all items from the binary heap. Since the underlying binary heap is now empty, the return value is the underlying binary heap that that is empty but still allocated.
use populated::PopulatedBinaryHeap;
use std::num::NonZeroUsize;
let mut binary_heap = PopulatedBinaryHeap::with_capacity(NonZeroUsize::new(5).unwrap(), 1);
binary_heap.push(2);
binary_heap.push(3);
let binary_heap = binary_heap.clear();
assert_eq!(binary_heap.len(), 0);
assert_eq!(binary_heap.capacity(), 5);Trait Implementations§
Source§impl<T: Clone> Clone for PopulatedBinaryHeap<T>
impl<T: Clone> Clone for PopulatedBinaryHeap<T>
Source§fn clone(&self) -> PopulatedBinaryHeap<T>
fn clone(&self) -> PopulatedBinaryHeap<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug> Debug for PopulatedBinaryHeap<T>
impl<T: Debug> Debug for PopulatedBinaryHeap<T>
Source§impl<T> From<PopulatedBinaryHeap<T>> for PopulatedVec<T>
impl<T> From<PopulatedBinaryHeap<T>> for PopulatedVec<T>
Source§fn from(populated_binary_heap: PopulatedBinaryHeap<T>) -> PopulatedVec<T>
fn from(populated_binary_heap: PopulatedBinaryHeap<T>) -> PopulatedVec<T>
Source§impl<T: Ord> From<PopulatedVec<T>> for PopulatedBinaryHeap<T>
impl<T: Ord> From<PopulatedVec<T>> for PopulatedBinaryHeap<T>
Source§fn from(populated_vec: PopulatedVec<T>) -> PopulatedBinaryHeap<T>
fn from(populated_vec: PopulatedVec<T>) -> PopulatedBinaryHeap<T>
Source§impl<T: Ord> FromPopulatedIterator<T> for PopulatedBinaryHeap<T>
impl<T: Ord> FromPopulatedIterator<T> for PopulatedBinaryHeap<T>
Source§fn from_populated_iter(iter: impl IntoPopulatedIterator<Item = T>) -> Self
fn from_populated_iter(iter: impl IntoPopulatedIterator<Item = T>) -> Self
PopulatedIterator into Self.Source§impl<'a, T> IntoIterator for &'a PopulatedBinaryHeap<T>
impl<'a, T> IntoIterator for &'a PopulatedBinaryHeap<T>
Source§impl<T> IntoIterator for PopulatedBinaryHeap<T>
impl<T> IntoIterator for PopulatedBinaryHeap<T>
Source§impl<'a, T> IntoPopulatedIterator for &'a PopulatedBinaryHeap<T>
impl<'a, T> IntoPopulatedIterator for &'a PopulatedBinaryHeap<T>
type PopulatedIntoIter = PopulatedIter<'a, T>
Source§fn into_populated_iter(self) -> PopulatedIter<'a, T>
fn into_populated_iter(self) -> PopulatedIter<'a, T>
PopulatedIterator.Source§impl<T> IntoPopulatedIterator for PopulatedBinaryHeap<T>
impl<T> IntoPopulatedIterator for PopulatedBinaryHeap<T>
type PopulatedIntoIter = IntoPopulatedIter<T>
Source§fn into_populated_iter(self) -> IntoPopulatedIter<T>
fn into_populated_iter(self) -> IntoPopulatedIter<T>
PopulatedIterator.