Struct containers::collections::heap::Heap [] [src]

pub struct Heap<T, Arity: Unsigned = U2, Rel: TotalOrderRelation<T> = Ord>(_, _);

Growable heap in terms of Vec

Methods

impl<T, Arity: Unsigned, Rel: TotalOrderRelation<T>> Heap<T, Arity, Rel>
[src]

fn new() -> Self

Make a new heap.

fn with_capacity(cap: usize) -> Option<Self>

Make a new heap with enough room to hold at least cap elements.

Failures

Returns None if allocation fails.

fn length(&self) -> usize

Return number of elements in heap.

fn capacity(&self) -> usize

Return number of elements heap can hold before reallocation.

fn reserve(&mut self, n_more: usize) -> bool

Make sure the heap has enough room for at least n_more more elements, reallocating if need be.

Failures

Returns false if allocation fails, true otherwise.

fn from_vec(v: Vec<T>) -> Self

Build a heap of the elements of v.

fn push(&mut self, x: T) -> Result<(), T>

Push an element into the heap.

fn pop(&mut self) -> Option<T>

Pop the root element off the heap and return it; return None if heap empty.

fn peek(&self) -> Option<&T>

Return a reference to root element, or None if heap empty.

fn peek_mut(&mut self) -> Option<&T>

Return a mutable reference to root element, or None if heap empty.

fn push_pop(&mut self, x: T) -> T

Pops the root and inserts the given value. xs being empty is an error.

fn into_vec(self) -> Vec<T>

Return a Vec of elements of heap in unspecified order.

fn into_sorted_vec(self) -> Vec<T>

Return a Vec of elements of heap in sorted order.