Struct ink_storage::collections::BinaryHeap [−][src]
A priority queue implemented with a binary heap.
Note
The heap is a max-heap by default, i.e. the first element is the largest.
Either Reverse
or a custom Ord
implementation can be used to
make BinaryHeap
a min-heap. This makes heap.pop()
return the smallest
value instead of the largest one.
Implementations
impl<T> BinaryHeap<T> where
T: PackedLayout + Ord,
[src]
T: PackedLayout + Ord,
pub fn new() -> Self
[src]
Creates a new empty storage heap.
pub fn len(&self) -> u32
[src]
Returns the number of elements in the heap, also referred to as its ‘length’.
pub fn is_empty(&self) -> bool
[src]
Returns true
if the heap contains no elements.
impl<T> BinaryHeap<T> where
T: PackedLayout + Ord,
[src]
T: PackedLayout + Ord,
pub fn iter(&self) -> Iter<'_, T>ⓘ
[src]
Returns an iterator yielding shared references to all elements of the heap.
Note
Avoid unbounded iteration over large heaps.
Prefer using methods like Iterator::take
in order to limit the number
of yielded elements.
pub fn peek(&self) -> Option<&T>
[src]
Returns a shared reference to the greatest element of the heap
Returns None
if the heap is empty
pub fn peek_mut(&mut self) -> Option<PeekMut<'_, T>>
[src]
Returns an exclusive reference to the greatest element of the heap
Returns None
if the heap is empty
Note:
If the PeekMut
value is leaked, the heap may be in an inconsistent state.
Example
use ink_storage::collections::BinaryHeap; let mut heap = BinaryHeap::new(); assert!(heap.peek_mut().is_none()); heap.push(1); heap.push(5); heap.push(2); { let mut val = heap.peek_mut().unwrap(); *val = 0; } assert_eq!(heap.peek(), Some(&2));
pub fn pop(&mut self) -> Option<T>
[src]
Pops greatest element from the heap and returns it
Returns None
if the heap is empty
pub fn clear(&mut self)
[src]
Removes all elements from this heap.
Note
Use this method to clear the heap instead of e.g. iterative pop()
.
This method performs significantly better and does not actually read
any of the elements (whereas pop()
does).
impl<T> BinaryHeap<T> where
T: PackedLayout + Ord,
[src]
T: PackedLayout + Ord,
Trait Implementations
impl<T: Debug> Debug for BinaryHeap<T> where
T: PackedLayout + Ord,
[src]
T: PackedLayout + Ord,
impl<T: Default> Default for BinaryHeap<T> where
T: PackedLayout + Ord,
[src]
T: PackedLayout + Ord,
fn default() -> BinaryHeap<T>
[src]
impl<T: Eq> Eq for BinaryHeap<T> where
T: PackedLayout + Ord,
[src]
T: PackedLayout + Ord,
impl<T> Extend<T> for BinaryHeap<T> where
T: PackedLayout + Ord,
[src]
T: PackedLayout + Ord,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
pub fn extend_one(&mut self, item: A)
[src]
pub fn extend_reserve(&mut self, additional: usize)
[src]
impl<T> FromIterator<T> for BinaryHeap<T> where
T: PackedLayout + Ord,
[src]
T: PackedLayout + Ord,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
impl<T: PartialEq> PartialEq<BinaryHeap<T>> for BinaryHeap<T> where
T: PackedLayout + Ord,
[src]
T: PackedLayout + Ord,
fn eq(&self, other: &BinaryHeap<T>) -> bool
[src]
fn ne(&self, other: &BinaryHeap<T>) -> bool
[src]
impl<T> SpreadLayout for BinaryHeap<T> where
T: PackedLayout + Ord,
[src]
T: PackedLayout + Ord,
const FOOTPRINT: u64
[src]
fn pull_spread(ptr: &mut KeyPtr) -> Self
[src]
fn push_spread(&self, ptr: &mut KeyPtr)
[src]
fn clear_spread(&self, ptr: &mut KeyPtr)
[src]
const REQUIRES_DEEP_CLEAN_UP: bool
[src]
impl<T> StorageLayout for BinaryHeap<T> where
T: PackedLayout + Ord + TypeInfo + 'static,
[src]
T: PackedLayout + Ord + TypeInfo + 'static,
impl<T> StructuralEq for BinaryHeap<T> where
T: PackedLayout + Ord,
[src]
T: PackedLayout + Ord,
impl<T> StructuralPartialEq for BinaryHeap<T> where
T: PackedLayout + Ord,
[src]
T: PackedLayout + Ord,
Auto Trait Implementations
impl<T> !RefUnwindSafe for BinaryHeap<T>
impl<T> Send for BinaryHeap<T> where
T: Send,
T: Send,
impl<T> !Sync for BinaryHeap<T>
impl<T> Unpin for BinaryHeap<T>
impl<T> !UnwindSafe for BinaryHeap<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,