Skip to content

Commit 3c2d60b

Browse files
Update Queue to Swift 3
1 parent 9ecfd88 commit 3c2d60b

File tree

7 files changed

+23
-15
lines changed

7 files changed

+23
-15
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ script:
2929
# - xcodebuild test -project ./Longest\ Common\ Subsequence/Tests/Tests.xcodeproj -scheme Tests
3030
# - xcodebuild test -project ./Minimum\ Spanning\ Tree\ \(Unweighted\)/Tests/Tests.xcodeproj -scheme Tests
3131
# - xcodebuild test -project ./Priority\ Queue/Tests/Tests.xcodeproj -scheme Tests
32-
# - xcodebuild test -project ./Queue/Tests/Tests.xcodeproj -scheme Tests
32+
- xcodebuild test -project ./Queue/Tests/Tests.xcodeproj -scheme Tests
3333
# - xcodebuild test -project ./Quicksort/Tests/Tests.xcodeproj -scheme Tests
3434
# - xcodebuild test -project ./Run-Length\ Encoding/Tests/Tests.xcodeproj -scheme Tests
3535
# - xcodebuild test -project ./Select\ Minimum\ Maximum/Tests/Tests.xcodeproj -scheme Tests

Queue/Queue-Optimized.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
Enqueuing and dequeuing are O(1) operations.
88
*/
99
public struct Queue<T> {
10-
private var array = [T?]()
11-
private var head = 0
10+
fileprivate var array = [T?]()
11+
fileprivate var head = 0
1212

1313
public var isEmpty: Bool {
1414
return count == 0
@@ -18,7 +18,7 @@ public struct Queue<T> {
1818
return array.count - head
1919
}
2020

21-
public mutating func enqueue(element: T) {
21+
public mutating func enqueue(_ element: T) {
2222
array.append(element)
2323
}
2424

Queue/Queue-Simple.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
implemented with a linked list, then both would be O(1).
99
*/
1010
public struct Queue<T> {
11-
private var array = [T]()
11+
fileprivate var array = [T]()
1212

1313
public var count: Int {
1414
return array.count
@@ -18,7 +18,7 @@ public struct Queue<T> {
1818
return array.isEmpty
1919
}
2020

21-
public mutating func enqueue(element: T) {
21+
public mutating func enqueue(_ element: T) {
2222
array.append(element)
2323
}
2424

Queue/Queue.playground/Contents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313

1414
public struct Queue<T> {
15-
private var array = [T]()
15+
fileprivate var array = [T]()
1616

1717
public var isEmpty: Bool {
1818
return array.isEmpty
@@ -22,7 +22,7 @@ public struct Queue<T> {
2222
return array.count
2323
}
2424

25-
public mutating func enqueue(element: T) {
25+
public mutating func enqueue(_ element: T) {
2626
array.append(element)
2727
}
2828

Queue/README.markdown

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Here is a very simplistic implementation of a queue in Swift. It's just a wrappe
4646

4747
```swift
4848
public struct Queue<T> {
49-
private var array = [T]()
49+
fileprivate var array = [T]()
5050

5151
public var isEmpty: Bool {
5252
return array.isEmpty
@@ -56,7 +56,7 @@ public struct Queue<T> {
5656
return array.count
5757
}
5858

59-
public mutating func enqueue(element: T) {
59+
public mutating func enqueue(_ element: T) {
6060
array.append(element)
6161
}
6262

@@ -136,8 +136,8 @@ Here is how you could implement this version of `Queue`:
136136

137137
```swift
138138
public struct Queue<T> {
139-
private var array = [T?]()
140-
private var head = 0
139+
fileprivate var array = [T?]()
140+
fileprivate var head = 0
141141

142142
public var isEmpty: Bool {
143143
return count == 0
@@ -147,7 +147,7 @@ public struct Queue<T> {
147147
return array.count - head
148148
}
149149

150-
public mutating func enqueue(element: T) {
150+
public mutating func enqueue(_ element: T) {
151151
array.append(element)
152152
}
153153

Queue/Tests/Tests.xcodeproj/project.pbxproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@
8383
isa = PBXProject;
8484
attributes = {
8585
LastSwiftUpdateCheck = 0720;
86-
LastUpgradeCheck = 0720;
86+
LastUpgradeCheck = 0800;
8787
ORGANIZATIONNAME = "Swift Algorithm Club";
8888
TargetAttributes = {
8989
7B2BBC7F1C779D720067B71D = {
9090
CreatedOnToolsVersion = 7.2;
91+
LastSwiftMigration = 0800;
9192
};
9293
};
9394
};
@@ -145,8 +146,10 @@
145146
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
146147
CLANG_WARN_EMPTY_BODY = YES;
147148
CLANG_WARN_ENUM_CONVERSION = YES;
149+
CLANG_WARN_INFINITE_RECURSION = YES;
148150
CLANG_WARN_INT_CONVERSION = YES;
149151
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
152+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
150153
CLANG_WARN_UNREACHABLE_CODE = YES;
151154
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
152155
CODE_SIGN_IDENTITY = "-";
@@ -189,8 +192,10 @@
189192
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
190193
CLANG_WARN_EMPTY_BODY = YES;
191194
CLANG_WARN_ENUM_CONVERSION = YES;
195+
CLANG_WARN_INFINITE_RECURSION = YES;
192196
CLANG_WARN_INT_CONVERSION = YES;
193197
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
198+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
194199
CLANG_WARN_UNREACHABLE_CODE = YES;
195200
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
196201
CODE_SIGN_IDENTITY = "-";
@@ -209,6 +214,7 @@
209214
MACOSX_DEPLOYMENT_TARGET = 10.11;
210215
MTL_ENABLE_DEBUG_INFO = NO;
211216
SDKROOT = macosx;
217+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
212218
};
213219
name = Release;
214220
};
@@ -220,6 +226,7 @@
220226
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
221227
PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests;
222228
PRODUCT_NAME = "$(TARGET_NAME)";
229+
SWIFT_VERSION = 3.0;
223230
};
224231
name = Debug;
225232
};
@@ -231,6 +238,7 @@
231238
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
232239
PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests;
233240
PRODUCT_NAME = "$(TARGET_NAME)";
241+
SWIFT_VERSION = 3.0;
234242
};
235243
name = Release;
236244
};

Queue/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0720"
3+
LastUpgradeVersion = "0800"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

0 commit comments

Comments
 (0)