PriorityQueue

public struct PriorityQueue<T> where T : Comparable
extension PriorityQueue: IteratorProtocol
extension PriorityQueue: Sequence
extension PriorityQueue: Collection
extension PriorityQueue: CustomStringConvertible, CustomDebugStringConvertible

A PriorityQueue takes objects to be pushed of any type that implements Comparable. It will pop the objects in the order that they would be sorted. A pop() or a push() can be accomplished in O(lg n) time. It can be specified whether the objects should be popped in ascending or descending order (Max Priority Queue or Min Priority Queue) at the time of initialization.

  • Undocumented

    Declaration

    Swift

    public init(ascending: Bool = false, startingValues: [T] = [])
  • Creates a new PriorityQueue with the given ordering.

    Declaration

    Swift

    public init(order: @escaping (T, T) -> Bool, startingValues: [T] = [])

    Parameters

    order

    A function that specifies whether its first argument should come after the second argument in the PriorityQueue.

    startingValues

    An array of elements to initialize the PriorityQueue with.

  • How many elements the Priority Queue stores

    Declaration

    Swift

    public var count: Int { get }
  • true if and only if the Priority Queue is empty

    Declaration

    Swift

    public var isEmpty: Bool { get }
  • Add a new element onto the Priority Queue. O(lg n)

    Declaration

    Swift

    public mutating func push(_ element: T)

    Parameters

    element

    The element to be inserted into the Priority Queue.

  • Remove and return the element with the highest priority (or lowest if ascending). O(lg n)

    Declaration

    Swift

    public mutating func pop() -> T?

    Return Value

    The element with the highest priority in the Priority Queue, or nil if the PriorityQueue is empty.

  • Removes the first occurence of a particular item. Finds it by value comparison using ==. O(n) Silently exits if no occurrence found.

    Declaration

    Swift

    public mutating func remove(_ item: T)

    Parameters

    item

    The item to remove the first occurrence of.

  • Removes all occurences of a particular item. Finds it by value comparison using ==. O(n) Silently exits if no occurrence found.

    Declaration

    Swift

    public mutating func removeAll(_ item: T)

    Parameters

    item

    The item to remove.

  • Get a look at the current highest priority item, without removing it. O(1)

    Declaration

    Swift

    public func peek() -> T?

    Return Value

    The element with the highest priority in the PriorityQueue, or nil if the PriorityQueue is empty.

  • Eliminate all of the elements from the Priority Queue.

    Declaration

    Swift

    public mutating func clear()

GeneratorType

SequenceType

CollectionType

CustomStringConvertible, CustomDebugStringConvertible