pub struct MaxHeap<T> { /* private fields */ }Expand description
Structure for holding n Option
Implementations§
Source§impl<T: Copy + PartialOrd> MaxHeap<T>
impl<T: Copy + PartialOrd> MaxHeap<T>
Sourcepub fn new() -> MaxHeap<T>
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());Sourcepub fn push(&mut self, item: T)
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!();
}Sourcepub fn pop(&mut self) -> Option<T>
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());pub fn peek(&self) -> Option<&T>
Sourcepub fn is_empty(&self) -> bool
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());Sourcepub fn len(&self) -> usize
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())pub fn clear(&mut self)
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more