pub struct BoundedBinaryHeap<T> { /* private fields */ }
Expand description
Binary heap with bound
Implementations§
Source§impl<T: PartialOrd + Clone> BoundedBinaryHeap<T>
impl<T: PartialOrd + Clone> BoundedBinaryHeap<T>
Sourcepub fn new(capacity: usize) -> BoundedBinaryHeap<T>
pub fn new(capacity: usize) -> BoundedBinaryHeap<T>
Constructor, create a new BoundedBinaryHeap with capacity
extern crate rust_heap;
use rust_heap::heap::BoundedBinaryHeap;
let h:BoundedBinaryHeap<i32> = BoundedBinaryHeap::new(3);
assert_eq!(h.capacity(), 3);
assert_eq!(h.len(), 0);
assert!(h.is_empty());
Sourcepub fn from(slice: &[T]) -> BoundedBinaryHeap<T>
pub fn from(slice: &[T]) -> BoundedBinaryHeap<T>
Constructor, create a new BoundedBinaryHeap from the content of a slice
extern crate rust_heap;
use rust_heap::heap::BoundedBinaryHeap;
let h = BoundedBinaryHeap::from(&[1,2,3,4,5]);
assert_eq!(h.capacity(), 5);
assert_eq!(h.len(), 5);
Sourcepub fn from_slice_with_capacity(
slice: &[T],
capacity: usize,
) -> BoundedBinaryHeap<T>
pub fn from_slice_with_capacity( slice: &[T], capacity: usize, ) -> BoundedBinaryHeap<T>
Constructor, create a new BoundedBinaryHeap from the content of a slice with given capacity
extern crate rust_heap;
use rust_heap::heap::BoundedBinaryHeap;
let h = BoundedBinaryHeap::from_slice_with_capacity(&[1,2,3], 5);
assert_eq!(h.capacity(), 5);
assert_eq!(h.len(), 3);
Sourcepub fn push(&mut self, elem: T) -> Option<T>
pub fn push(&mut self, elem: T) -> Option<T>
Push a value into heap if value>=root and keep heap structure Overflow and return the smallest element when heap is full
extern crate rust_heap;
use rust_heap::heap::BoundedBinaryHeap;
let mut h = BoundedBinaryHeap::from(&[1,2,3]);
assert_eq!(h.push(4).unwrap(), 1);
assert_eq!(h.len(), 3);
Auto Trait Implementations§
impl<T> Freeze for BoundedBinaryHeap<T>
impl<T> RefUnwindSafe for BoundedBinaryHeap<T>where
T: RefUnwindSafe,
impl<T> Send for BoundedBinaryHeap<T>where
T: Send,
impl<T> Sync for BoundedBinaryHeap<T>where
T: Sync,
impl<T> Unpin for BoundedBinaryHeap<T>where
T: Unpin,
impl<T> UnwindSafe for BoundedBinaryHeap<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