GenericMaxPriorityQueue
public struct GenericMaxPriorityQueue<
Priority: Comparable,
Payload,
Heap: RandomAccessCollection & RangeReplaceableCollection & MutableCollection,
ElementLocations: PriorityQueueIndexer
>: Queue where
Heap.Element == PriorityQueueElement<Priority, Payload>,
ElementLocations.Key == Payload,
ElementLocations.Value == Heap.Index
extension GenericMaxPriorityQueue: RandomAccessCollection
extension GenericMaxPriorityQueue: CustomStringConvertible
extension GenericMaxPriorityQueue: DefaultInitializable
where
Heap: DefaultInitializable,
ElementLocations: DefaultInitializable
A collection of Priority
s and Payload
s that allows for efficient retrieval of the smallest
priority and its associated payload, and insertion of payloads at arbitrary priorities.
This is a max-priority queue, where a
has “higher priority” than b
if a < b
.
See also
SimpleMaxPriorityQueue
.
-
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
element
intoself
and updates the internal data structures to maintain efficiency.Declaration
Swift
public mutating func push(_ element: Element)
-
Adds
payload
intoself
at 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.isMaxHeap
Declaration
Swift
public init(_ heap: Heap)
-
Updates the priority of
payload
tonewPriority
.Precondition
payload
is contained withinself
.Complexity
O(log n)Declaration
Swift
@discardableResult public mutating func update(_ payload: Payload, withNewPriority newPriority: Priority) -> Priority
Return Value
the previous priority of
elem
.