Skip to content

Commit bd0c74e

Browse files
committed
Refactor to remove dependency on pre-Swift 4.
The code used to depend on pre-Swift 4's optional operators, which have since been replaced. Now, the one possible case for comparing a potential `nil` maximum value has been handled.
1 parent 6ab163e commit bd0c74e

File tree

1 file changed

+5
-26
lines changed

1 file changed

+5
-26
lines changed

Bucket Sort/BucketSort.swift

+5-26
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,6 @@
2020
//
2121
//
2222

23-
import Foundation
24-
// FIXME: comparison operators with optionals were removed from the Swift Standard Libary.
25-
// Consider refactoring the code to use the non-optional operators.
26-
fileprivate func < <T: Comparable>(lhs: T?, rhs: T?) -> Bool {
27-
switch (lhs, rhs) {
28-
case let (l?, r?):
29-
return l < r
30-
case (nil, _?):
31-
return true
32-
default:
33-
return false
34-
}
35-
}
36-
37-
// FIXME: comparison operators with optionals were removed from the Swift Standard Libary.
38-
// Consider refactoring the code to use the non-optional operators.
39-
fileprivate func >= <T: Comparable>(lhs: T?, rhs: T?) -> Bool {
40-
switch (lhs, rhs) {
41-
case let (l?, r?):
42-
return l >= r
43-
default:
44-
return !(lhs < rhs)
45-
}
46-
}
47-
4823
//////////////////////////////////////
4924
// MARK: Main algorithm
5025
//////////////////////////////////////
@@ -87,7 +62,11 @@ private func enoughSpaceInBuckets<T>(_ buckets: [Bucket<T>], elements: [T]) -> B
8762
let maximumValue = elements.max()?.toInt()
8863
let totalCapacity = buckets.count * (buckets.first?.capacity)!
8964

90-
return totalCapacity >= maximumValue
65+
guard let max = maximumValue else {
66+
return false
67+
}
68+
69+
return totalCapacity >= max
9170
}
9271

9372
//////////////////////////////////////

0 commit comments

Comments
 (0)