@@ -13,24 +13,28 @@ import Swift
13
13
14
14
/// A double-ended priority queue built on top of `Heap`.
15
15
public struct PriorityQueue < Value, Priority: Comparable > {
16
- public typealias Element = ( value: Value , priority: Priority )
16
+ public typealias Pair = ( value: Value , priority: Priority )
17
17
18
- public struct Pair : Comparable {
18
+ @usableFromInline
19
+ struct Element : Comparable {
19
20
@usableFromInline let value : Value
20
21
let priority : Priority
21
22
let insertionCounter : UInt64
22
23
23
- public init ( value: Value , priority: Priority , insertionCounter: UInt64 ) {
24
+ @usableFromInline
25
+ init ( value: Value , priority: Priority , insertionCounter: UInt64 ) {
24
26
self . value = value
25
27
self . priority = priority
26
28
self . insertionCounter = insertionCounter
27
29
}
28
30
29
- public static func == ( lhs: Self , rhs: Self ) -> Bool {
31
+ @usableFromInline
32
+ static func == ( lhs: Self , rhs: Self ) -> Bool {
30
33
lhs. priority == rhs. priority
31
34
}
32
35
33
- public static func < ( lhs: Self , rhs: Self ) -> Bool {
36
+ @usableFromInline
37
+ static func < ( lhs: Self , rhs: Self ) -> Bool {
34
38
if lhs. priority < rhs. priority {
35
39
return true
36
40
} else if lhs. priority == rhs. priority {
@@ -42,7 +46,7 @@ public struct PriorityQueue<Value, Priority: Comparable> {
42
46
}
43
47
44
48
@usableFromInline
45
- internal var _base : Heap < Pair >
49
+ internal var _base : Heap < Element >
46
50
47
51
@usableFromInline
48
52
internal var _insertionCounter : UInt64 = 0
@@ -78,7 +82,7 @@ public struct PriorityQueue<Value, Priority: Comparable> {
78
82
public mutating func insert( _ value: Value , priority: Priority ) {
79
83
defer { _insertionCounter += 1 }
80
84
81
- let pair = Pair (
85
+ let pair = Element (
82
86
value: value,
83
87
priority: priority,
84
88
insertionCounter: _insertionCounter
@@ -147,12 +151,12 @@ extension PriorityQueue {
147
151
///
148
152
/// - Complexity: O(n), where `n` is the length of `elements`.
149
153
@inlinable
150
- public init < S: Sequence > ( _ elements: S ) where S. Element == Element {
154
+ public init < S: Sequence > ( _ elements: S ) where S. Element == Pair {
151
155
_base = Heap (
152
156
elements
153
157
. enumerated ( )
154
158
. map ( {
155
- Pair (
159
+ Element (
156
160
value: $0. element. value,
157
161
priority: $0. element. priority,
158
162
insertionCounter: UInt64 ( $0. offset)
0 commit comments