PopulatedBinaryHeap

Struct PopulatedBinaryHeap 

Source
pub struct PopulatedBinaryHeap<T>(/* private fields */);

Implementations§

Source§

impl<T: Ord> PopulatedBinaryHeap<T>

Source

pub fn new(value: T) -> PopulatedBinaryHeap<T>

Creates a binary heap populated with a single value.

Source

pub fn with_capacity(capacity: NonZeroUsize, value: T) -> PopulatedBinaryHeap<T>

Creates a binary populated with a single value and the given capacity.

Source

pub fn push(&mut self, item: T)

Pushes an item onto the binary heap.

Source

pub fn into_sorted_vec(self) -> PopulatedVec<T>

Consumes the PopulatedBinaryHeap and returns a populated vector in sorted (ascending) order.

Source

pub fn append(&mut self, other: &mut BinaryHeap<T>)

Moves all the elements of other into self, leaving other empty.

Source

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);
Source

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>

Source

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);
Source

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());
Source

pub fn shrink_to_fit(&mut self)

Discards as much additional capacity as possible. The capacity will never be less than the length.

Source

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);
Source

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);
Source

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>

Source§

fn clone(&self) -> PopulatedBinaryHeap<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for PopulatedBinaryHeap<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> From<PopulatedBinaryHeap<T>> for PopulatedVec<T>

Source§

fn from(populated_binary_heap: PopulatedBinaryHeap<T>) -> PopulatedVec<T>

Converts to this type from the input type.
Source§

impl<T: Ord> From<PopulatedVec<T>> for PopulatedBinaryHeap<T>

Source§

fn from(populated_vec: PopulatedVec<T>) -> PopulatedBinaryHeap<T>

Converts to this type from the input type.
Source§

impl<T: Ord> FromPopulatedIterator<T> for PopulatedBinaryHeap<T>

Source§

fn from_populated_iter(iter: impl IntoPopulatedIterator<Item = T>) -> Self

Converts a PopulatedIterator into Self.
Source§

impl<'a, T> IntoIterator for &'a PopulatedBinaryHeap<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> IntoIterator for PopulatedBinaryHeap<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> IntoPopulatedIterator for &'a PopulatedBinaryHeap<T>

Source§

type PopulatedIntoIter = PopulatedIter<'a, T>

Source§

fn into_populated_iter(self) -> PopulatedIter<'a, T>

Converts the type into a PopulatedIterator.
Source§

impl<T> IntoPopulatedIterator for PopulatedBinaryHeap<T>

Source§

type PopulatedIntoIter = IntoPopulatedIter<T>

Source§

fn into_populated_iter(self) -> IntoPopulatedIter<T>

Converts the type into a PopulatedIterator.

Auto Trait Implementations§

§

impl<T> Freeze for PopulatedBinaryHeap<T>

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for PopulatedBinaryHeap<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.