docs

您正在閱讀 v0.1.0 的文件。Nabi 0.1.0 已停止支援。 最新版本:v0.1.3 →

core::collections::heap

本頁內容

API 參考只有英文版,由標準函式庫原始碼中的英文文件註解產生。

BinaryHeap<T>, a priority queue over a List laid out as an implicit binary tree. new() pops the greatest item first; by_ordering(cmp) pops the greatest by cmp.

Structs

BinaryHeapSource

pub struct BinaryHeap<T>

A priority queue: new() pops the greatest item first, by_ordering(cmp) the greatest by cmp.

  • pub const fn new() -> BinaryHeap<T>§

    Source

    A max-heap.

  • pub const fn by_ordering(cmp: fn(T, T) -> core::cmp::Ordering + Send) -> BinaryHeap<T>§

    Source

    A heap whose top is the greatest item by cmp, as new() is by Ord::cmp: by_ordering(|a, b| b.cmp(a)) pops the least first.

  • pub const fn len(self) -> usize§

    Source

    The number of items.

  • pub const fn is_empty(self) -> bool§

    Source

    true when the heap holds no item.

  • pub const fn peek(self) -> T | none§

    Source

    The top item.

  • pub const fn push(self, x: T)§

    Source

    Add x; O(log n).

  • pub const fn pop(self) -> T | none§

    Source

    Remove and return the top item; O(log n).

  • pub const fn clear(self)§

    Source

    Drop every item.

  • pub const fn retain(self, keep: fn(T) -> bool)§

    Source

    Keep only the items keep accepts, in place; O(n).

  • pub const fn iter(self) -> HeapIter<T>§

    Source

    Every item, in no particular order.

Trait implementations 6

HeapIterSource

pub struct HeapIter<T>

The items of a heap, in no particular order.

Trait implementations 3