MaxHeap

Struct MaxHeap 

Source
pub struct MaxHeap<T> { /* private fields */ }
Expand description

Structure for holding n Option values

Implementations§

Source§

impl<T: Copy + PartialOrd> MaxHeap<T>

Source

pub fn new() -> MaxHeap<T>

Create a new binary heap

§Examples
use nostbeep::MaxHeap;
let mut my_heap: MaxHeap<i32> = MaxHeap::new();
assert_eq!(0, my_heap.len());
Source

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

Add an item of type T to the heap.

§Examples
use nostbeep::MaxHeap;
let val1 = -3;
let val2 = 17;
let mut my_heap = MaxHeap::new();
my_heap.push(val1);
my_heap.push(val2);

assert_eq!(2, my_heap.len());
if let Some(v) = my_heap.peek() {
       assert_eq!(val2, *v);
} else {
       panic!();
}
Source

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

Remove the item from the top of the heap.

§Examples
use nostbeep::MaxHeap;
let val1 = 17;
let val2 = -5;
let val3 = 100;
let mut my_heap = MaxHeap::new();
my_heap.push(val1);
my_heap.push(val2);
my_heap.push(val3);

my_heap.pop();
my_heap.pop();
assert_eq!(Some(val2), my_heap.pop());
Source

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

Source

pub fn is_empty(&self) -> bool

Check if the heap is empty

§Examples
use nostbeep::MaxHeap;
let mut my_heap = MaxHeap::new();
my_heap.push(17);
my_heap.push(-3);
assert!(!my_heap.is_empty());
Source

pub fn len(&self) -> usize

Return the length of the heap.

§Examples
use nostbeep::MaxHeap;
let mut my_heap = MaxHeap::new();
my_heap.push(17);
my_heap.push(-3);
assert_eq!(2, my_heap.len())
Source

pub fn clear(&mut self)

Trait Implementations§

Source§

impl<T: Copy + PartialOrd> Default for MaxHeap<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for MaxHeap<T>
where T: Freeze,

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for MaxHeap<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> 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, 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.