GenericPriorityQueue
public struct GenericPriorityQueue<
Priority: Comparable,
Payload,
Heap: RandomAccessCollection & RangeReplaceableCollection & MutableCollection,
ElementLocations: PriorityQueueIndexer
>: Queue where
Heap.Element == PriorityQueueElement<Priority, Payload>,
ElementLocations.Key == Payload,
ElementLocations.Value == Heap.Index
extension GenericPriorityQueue: RandomAccessCollection
extension GenericPriorityQueue: CustomStringConvertible
extension GenericPriorityQueue: DefaultInitializable
where
Heap: DefaultInitializable,
ElementLocations: DefaultInitializable
A collection of Prioritys and Payloads that allows for efficient retrieval of the smallest
priority and its associated payload, and insertion of payloads at arbitrary priorities.
This is a min-priority queue, where a has “higher priority” than b if a < b.
See also
SimplePriorityQueue.
-
The type of data in the underlying binary heap.
Declaration
Swift
public typealias Element = PriorityQueueElement<Priority, Payload> -
The heap data structure containing our priority queue.
Declaration
Swift
public var heap: Heap -
Undocumented
Declaration
Swift
public init(heap: Heap, locations: ElementLocations) -
The data at the top of the priority queue.
Declaration
Swift
public var top: Payload? { get } -
Removes and returns the top of
self.Declaration
Swift
@discardableResult public mutating func pop() -> Element? -
Adds
elementintoselfand updates the internal data structures to maintain efficiency.Declaration
Swift
public mutating func push(_ element: Element) -
Adds
payloadintoselfat priority levelpriority, and updates the internal data structures to maintain efficiency.Declaration
Swift
public mutating func push(_ payload: Payload, at priority: Priority)
-
Declaration
Swift
public var startIndex: Heap.Index { get } -
Declaration
Swift
public var endIndex: Heap.Index { get } -
Declaration
Swift
public subscript(index: Heap.Index) -> Element { get } -
Declaration
Swift
public func index(after index: Heap.Index) -> Heap.Index -
Declaration
Swift
public func index(before index: Heap.Index) -> Heap.Index -
A string representation of the heap, including priorities of the elements.
Declaration
Swift
public var description: String { get }
-
Constructs an empty GenericPriorityQueue.
Declaration
Swift
public init()
-
Constructs a GenericPriorityQueue from
heap.Precondition
heap.isMinHeapDeclaration
Swift
public init(_ heap: Heap)
-
Updates the priority of
payloadtonewPriority.Precondition
payloadis contained withinself.Complexity
O(log n)Declaration
Swift
@discardableResult public mutating func update(_ payload: Payload, withNewPriority newPriority: Priority) -> PriorityReturn Value
the previous priority of
elem.
View on GitHub
GenericPriorityQueue Structure Reference