1
- public class LinkedListNode < T: Comparable > {
1
+ open class LinkedListNode < T: Comparable > {
2
2
var value : T
3
3
var next : LinkedListNode ?
4
4
var previous : LinkedListNode ?
@@ -8,27 +8,27 @@ public class LinkedListNode<T: Comparable> {
8
8
}
9
9
}
10
10
11
- public class BoundedPriorityQueue < T: Comparable > {
12
- private typealias Node = LinkedListNode < T >
11
+ open class BoundedPriorityQueue < T: Comparable > {
12
+ fileprivate typealias Node = LinkedListNode < T >
13
13
14
- private ( set) public var count = 0
15
- private var head : Node ?
16
- private var tail : Node ?
17
- private var maxElements : Int
14
+ fileprivate ( set) open var count = 0
15
+ fileprivate var head : Node ?
16
+ fileprivate var tail : Node ?
17
+ fileprivate var maxElements : Int
18
18
19
19
public init ( maxElements: Int ) {
20
20
self . maxElements = maxElements
21
21
}
22
22
23
- public var isEmpty : Bool {
23
+ open var isEmpty : Bool {
24
24
return count == 0
25
25
}
26
26
27
- public func peek( ) -> T ? {
27
+ open func peek( ) -> T ? {
28
28
return head? . value
29
29
}
30
30
31
- public func enqueue( value: T ) {
31
+ open func enqueue( _ value: T ) {
32
32
if let node = insert ( value, after: findInsertionPoint ( value) ) {
33
33
// If the newly inserted node is the last one in the list, then update
34
34
// the tail pointer.
@@ -44,7 +44,7 @@ public class BoundedPriorityQueue<T: Comparable> {
44
44
}
45
45
}
46
46
47
- private func insert( value: T , after: Node ? ) -> Node ? {
47
+ fileprivate func insert( _ value: T , after: Node ? ) -> Node ? {
48
48
if let previous = after {
49
49
50
50
// If the queue is full and we have to insert at the end of the list,
@@ -78,18 +78,18 @@ public class BoundedPriorityQueue<T: Comparable> {
78
78
79
79
/* Find the node after which to insert the new value. If this returns nil,
80
80
the new value should be inserted at the head of the list. */
81
- private func findInsertionPoint( value: T ) -> Node ? {
81
+ fileprivate func findInsertionPoint( _ value: T ) -> Node ? {
82
82
var node = head
83
83
var prev : Node ? = nil
84
84
85
- while let current = node where value < current. value {
85
+ while let current = node, value < current. value {
86
86
prev = node
87
87
node = current. next
88
88
}
89
89
return prev
90
90
}
91
91
92
- private func removeLeastImportantElement( ) {
92
+ fileprivate func removeLeastImportantElement( ) {
93
93
if let last = tail {
94
94
tail = last. previous
95
95
tail? . next = nil
@@ -101,7 +101,7 @@ public class BoundedPriorityQueue<T: Comparable> {
101
101
// this is much slower on large lists.
102
102
}
103
103
104
- public func dequeue( ) -> T ? {
104
+ open func dequeue( ) -> T ? {
105
105
if let first = head {
106
106
count -= 1
107
107
if count == 0 {
0 commit comments