Skip to content

Commit 78ebf95

Browse files
authored
Merge pull request kodecocodes#778 from SpacyRicochet/migration/swift4-2_bucket-sort
[Swift 4.2] Bucket Sort
2 parents 310fbf4 + f289732 commit 78ebf95

File tree

7 files changed

+26
-58
lines changed

7 files changed

+26
-58
lines changed

Bucket Sort/BucketSort.playground/Sources/BucketSort.swift

Lines changed: 5 additions & 26 deletions
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
//////////////////////////////////////
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<playground version='5.0' target-platform='ios'>
2+
<playground version='5.0' target-platform='ios' executeOnSourceChanges='false'>
33
<timeline fileName='timeline.xctimeline'/>
44
</playground>

Bucket Sort/BucketSort.swift

Lines changed: 5 additions & 26 deletions
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
//////////////////////////////////////

Bucket Sort/README.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,4 @@ The following are some of the variation to the general [Bucket Sort](https://en.
256256
- [Postman Sort](https://en.wikipedia.org/wiki/Bucket_sort#Postman.27s_sort)
257257
- [Shuffle Sort](https://en.wikipedia.org/wiki/Bucket_sort#Shuffle_sort)
258258

259-
*Written for Swift Algorithm Club by Barbara Rodeker. Images from Wikipedia.*
259+
*Written for Swift Algorithm Club by Barbara Rodeker. Images from Wikipedia. Updated by Bruno Scheele.*

Bucket Sort/Tests/Tests.xcodeproj/project.pbxproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
isa = PBXProject;
8484
attributes = {
8585
LastSwiftUpdateCheck = 0730;
86-
LastUpgradeCheck = 0900;
86+
LastUpgradeCheck = 1000;
8787
ORGANIZATIONNAME = "Swift Algorithm Club";
8888
TargetAttributes = {
8989
7B2BBC7F1C779D720067B71D = {
@@ -145,12 +145,14 @@
145145
CLANG_WARN_BOOL_CONVERSION = YES;
146146
CLANG_WARN_COMMA = YES;
147147
CLANG_WARN_CONSTANT_CONVERSION = YES;
148+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
148149
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
149150
CLANG_WARN_EMPTY_BODY = YES;
150151
CLANG_WARN_ENUM_CONVERSION = YES;
151152
CLANG_WARN_INFINITE_RECURSION = YES;
152153
CLANG_WARN_INT_CONVERSION = YES;
153154
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
155+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
154156
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
155157
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
156158
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -197,12 +199,14 @@
197199
CLANG_WARN_BOOL_CONVERSION = YES;
198200
CLANG_WARN_COMMA = YES;
199201
CLANG_WARN_CONSTANT_CONVERSION = YES;
202+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
200203
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
201204
CLANG_WARN_EMPTY_BODY = YES;
202205
CLANG_WARN_ENUM_CONVERSION = YES;
203206
CLANG_WARN_INFINITE_RECURSION = YES;
204207
CLANG_WARN_INT_CONVERSION = YES;
205208
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
209+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
206210
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
207211
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
208212
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Bucket Sort/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0900"
3+
LastUpgradeVersion = "1000"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,7 +26,6 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
language = ""
3029
shouldUseLaunchSchemeArgsEnv = "YES">
3130
<Testables>
3231
<TestableReference
@@ -47,7 +46,6 @@
4746
buildConfiguration = "Debug"
4847
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4948
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
50-
language = ""
5149
launchStyle = "0"
5250
useCustomWorkingDirectory = "NO"
5351
ignoresPersistentStateOnLaunch = "NO"

0 commit comments

Comments
 (0)