Skip to content

Commit be7a4c7

Browse files
committed
Rename Pair -> Element and Element -> Pair
The type stored in the underlying heap has more than 2 values, so Pair is a misnomer. This has been renamed to 'Element.' The existing tyepalias Element has been renamed to 'Pair,' as it only includes the Value and its Priority.
1 parent 4e04a7f commit be7a4c7

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

Sources/PriorityQueueModule/PriorityQueue+ExpressibleByArrayLiteral.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension PriorityQueue: ExpressibleByArrayLiteral {
2323
/// - Parameter elements: A variadic list of tuples containing the element
2424
/// and its priority (in that order).
2525
@inlinable
26-
public init(arrayLiteral elements: Element...) {
26+
public init(arrayLiteral elements: Pair...) {
2727
self.init(elements)
2828
}
2929
}

Sources/PriorityQueueModule/PriorityQueue.swift

+13-9
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,28 @@ import Swift
1313

1414
/// A double-ended priority queue built on top of `Heap`.
1515
public struct PriorityQueue<Value, Priority: Comparable> {
16-
public typealias Element = (value: Value, priority: Priority)
16+
public typealias Pair = (value: Value, priority: Priority)
1717

18-
public struct Pair: Comparable {
18+
@usableFromInline
19+
struct Element: Comparable {
1920
@usableFromInline let value: Value
2021
let priority: Priority
2122
let insertionCounter: UInt64
2223

23-
public init(value: Value, priority: Priority, insertionCounter: UInt64) {
24+
@usableFromInline
25+
init(value: Value, priority: Priority, insertionCounter: UInt64) {
2426
self.value = value
2527
self.priority = priority
2628
self.insertionCounter = insertionCounter
2729
}
2830

29-
public static func == (lhs: Self, rhs: Self) -> Bool {
31+
@usableFromInline
32+
static func == (lhs: Self, rhs: Self) -> Bool {
3033
lhs.priority == rhs.priority
3134
}
3235

33-
public static func < (lhs: Self, rhs: Self) -> Bool {
36+
@usableFromInline
37+
static func < (lhs: Self, rhs: Self) -> Bool {
3438
if lhs.priority < rhs.priority {
3539
return true
3640
} else if lhs.priority == rhs.priority {
@@ -42,7 +46,7 @@ public struct PriorityQueue<Value, Priority: Comparable> {
4246
}
4347

4448
@usableFromInline
45-
internal var _base: Heap<Pair>
49+
internal var _base: Heap<Element>
4650

4751
@usableFromInline
4852
internal var _insertionCounter: UInt64 = 0
@@ -78,7 +82,7 @@ public struct PriorityQueue<Value, Priority: Comparable> {
7882
public mutating func insert(_ value: Value, priority: Priority) {
7983
defer { _insertionCounter += 1 }
8084

81-
let pair = Pair(
85+
let pair = Element(
8286
value: value,
8387
priority: priority,
8488
insertionCounter: _insertionCounter
@@ -147,12 +151,12 @@ extension PriorityQueue {
147151
///
148152
/// - Complexity: O(n), where `n` is the length of `elements`.
149153
@inlinable
150-
public init<S: Sequence>(_ elements: S) where S.Element == Element {
154+
public init<S: Sequence>(_ elements: S) where S.Element == Pair {
151155
_base = Heap(
152156
elements
153157
.enumerated()
154158
.map({
155-
Pair(
159+
Element(
156160
value: $0.element.value,
157161
priority: $0.element.priority,
158162
insertionCounter: UInt64($0.offset)

0 commit comments

Comments
 (0)