pub struct BinHeap<T>where
T: Ord,{ /* private fields */ }Expand description
Implementations§
Source§impl<T> BinHeap<T>where
T: Ord,
impl<T> BinHeap<T>where
T: Ord,
Sourcepub fn new_with_capacity(capacity: usize) -> Self
pub fn new_with_capacity(capacity: usize) -> Self
Creates a new BinHeap that pre-allocates to the given capacity.
Sourcepub fn from_slice(list: &[T]) -> Selfwhere
T: Clone,
pub fn from_slice(list: &[T]) -> Selfwhere
T: Clone,
A “heapify” operation that creates a BinHeap from any slice of entries
in O(n) time. The entries must be Clone.
Sourcepub fn from_vec(list: Vec<T>) -> Self
pub fn from_vec(list: Vec<T>) -> Self
A “heapify” operation that creates a BinHeap from a Vec<T> in O(n)
time. T does not need to be Clone.
Sourcepub fn peek(&self) -> Option<&T>
pub fn peek(&self) -> Option<&T>
Returns an immutable reference to the data at the top of the heap
in O(1) time.
Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Returns and removes the element at the top of the heap in O(log(n)) time.
Sourcepub fn heap_sort(list: &mut [T])where
T: Ord,
pub fn heap_sort(list: &mut [T])where
T: Ord,
Sorts a mutable slice into ascending order in place via (max) heap operations in O(n * log(n)) time.
use dsa_rust::hierarchies::bin_heap::BinHeap;
let mut v = Vec::from([8, 6, 7, 5, 3, 0, 9]);
BinHeap::heap_sort(&mut v);
assert_eq!(v, [0, 3, 5, 6, 7, 8, 9]);Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for BinHeap<T>
impl<T> RefUnwindSafe for BinHeap<T>where
T: RefUnwindSafe,
impl<T> Send for BinHeap<T>where
T: Send,
impl<T> Sync for BinHeap<T>where
T: Sync,
impl<T> Unpin for BinHeap<T>where
T: Unpin,
impl<T> UnwindSafe for BinHeap<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