Skip to content
FutureBlitz

    Install

    Import std.collections.priority_queue

    PriorityQueue

    std.collections.priority_queue

    class

    @DebugElements Public Class PriorityQueue<T> Implements Iterable<T>, Cloneable

    A heap that gives its values out first by a priority: the smallest first, or what a Function says comes first.

    Examples

    Local smallest = PriorityQueue<Int>()
    smallest.AddAll([5, 1, 4])
    Expect(smallest.Pop() == 1)
    Expect(smallest.Peek() == 4)
    Local largest = PriorityQueue<Int>(Function(a: Int, b: Int) => a > b)
    largest.AddAll([5, 1, 4])
    Expect(largest.Drain() == [5, 4, 1])

    std/collections/priority_queue.fb, line 25

    • Public New() constructor #

      A new, empty PriorityQueue that gives its smallest value first.

    • Public New(before: Func(T, T): Bool) constructor #

      A new, empty PriorityQueue that gives first the value before says comes before the others.

    • Public Property Count: Int property #

      How many values it holds.

    • @PanicsAtCaller Public Method Add(value: T) method #

      Puts value in.

    • @PanicsAtCaller Public Method AddAll(values: Iterable<T>) method #

      Adds each of the values, putting the heap in order once, in time that grows with the count.

    • @PanicsAtCaller Public Method Pop(): T method #

      Takes the first value off and gives it. Panics when the PriorityQueue is empty.

    • Public Method TryPop(): T? method #

      Takes the first value off and gives it, or Null when the PriorityQueue is empty.

    • Public Method TryPeek(): T? method #

      The first value, which stays, or Null when the PriorityQueue is empty.

    • Public Method Drain(): T[] method #

      Takes every value off, and gives them in the order Pop would.

    • Public Method ToArray(): T[] method #

      The values, in no particular order, in a new array.

    • @PanicsAtCaller Public Method Peek(): T method #

      The first value, which stays. Panics when the PriorityQueue is empty.

    • Public Method Contains(value: T): Bool method #

      Whether it holds value.

    • Public Method Clear() method #

      Takes every value out.

    • Public Method Clone(): PriorityQueue<T> method #

      A new PriorityQueue with the same values and order.

    • Public Method Iterate(): PriorityQueueIterator<T> method #

      The values, in no particular order: Pop gives them in order. Changing the PriorityQueue while going over them panics.

    Report an issue with this page or with FutureBlitz on GitHub.