Struct ink_storage::collections::BinaryHeap[][src]

pub struct BinaryHeap<T> where
    T: PackedLayout + Ord
{ /* fields omitted */ }

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]

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]

pub fn iter(&self) -> Iter<'_, T>

Notable traits for Iter<'a, T>

impl<'a, T> Iterator for Iter<'a, T> where
    T: PackedLayout + Ord
type Item = &'a 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]

pub fn push(&mut self, value: T)[src]

Pushes the given element to the binary heap.

Trait Implementations

impl<T: Debug> Debug for BinaryHeap<T> where
    T: PackedLayout + Ord
[src]

impl<T: Default> Default for BinaryHeap<T> where
    T: PackedLayout + Ord
[src]

impl<T: Eq> Eq for BinaryHeap<T> where
    T: PackedLayout + Ord
[src]

impl<T> Extend<T> for BinaryHeap<T> where
    T: PackedLayout + Ord
[src]

impl<T> FromIterator<T> for BinaryHeap<T> where
    T: PackedLayout + Ord
[src]

impl<T: PartialEq> PartialEq<BinaryHeap<T>> for BinaryHeap<T> where
    T: PackedLayout + Ord
[src]

impl<T> SpreadLayout for BinaryHeap<T> where
    T: PackedLayout + Ord
[src]

impl<T> StorageLayout for BinaryHeap<T> where
    T: PackedLayout + Ord + TypeInfo + 'static, 
[src]

impl<T> StructuralEq for BinaryHeap<T> where
    T: PackedLayout + Ord
[src]

impl<T> StructuralPartialEq for BinaryHeap<T> where
    T: PackedLayout + Ord
[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for BinaryHeap<T>

impl<T> Send for BinaryHeap<T> where
    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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

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]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,