Skip to content

Commit f971e72

Browse files
authored
Merge pull request #233 from JaapWijnen/update-priority-queue
Updated priority queue to swift 3
2 parents 4a211c3 + 9cb0ca2 commit f971e72

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

Priority Queue/PriorityQueue.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
queue (largest element first) or a min-priority queue (smallest element first).
1212
*/
1313
public struct PriorityQueue<T> {
14-
private var heap: Heap<T>
14+
fileprivate var heap: Heap<T>
1515

1616
/*
1717
To create a max-priority queue, supply a > sort function. For a min-priority
1818
queue, use <.
1919
*/
20-
public init(sort: (T, T) -> Bool) {
20+
public init(sort: @escaping (T, T) -> Bool) {
2121
heap = Heap(sort: sort)
2222
}
2323

@@ -33,7 +33,7 @@ public struct PriorityQueue<T> {
3333
return heap.peek()
3434
}
3535

36-
public mutating func enqueue(element: T) {
36+
public mutating func enqueue(_ element: T) {
3737
heap.insert(element)
3838
}
3939

@@ -52,7 +52,7 @@ public struct PriorityQueue<T> {
5252
}
5353

5454
extension PriorityQueue where T: Equatable {
55-
public func indexOf(element: T) -> Int? {
56-
return heap.indexOf(element)
55+
public func index(of element: T) -> Int? {
56+
return heap.index(of: element)
5757
}
5858
}

Priority Queue/README.markdown

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The queue can be a *max-priority* queue (largest element first) or a *min-priori
88

99
Priority queues are useful for algorithms that need to process a (large) number of items and where you repeatedly need to identify which one is now the biggest or smallest -- or however you define "most important".
1010

11-
Examples of algorithms that can benefit from a priority queue:
11+
Examples of algorithms that can benefit from a priority queue:
1212

1313
- Event-driven simulations. Each event is given a timestamp and you want events to be performed in order of their timestamps. The priority queue makes it easy to find the next event that needs to be simulated.
1414
- Dijkstra's algorithm for graph searching uses a priority queue to calculate the minimum cost.
@@ -39,7 +39,7 @@ Here's a Swift priority queue based on a heap:
3939

4040
```swift
4141
public struct PriorityQueue<T> {
42-
private var heap: Heap<T>
42+
fileprivate var heap: Heap<T>
4343

4444
public init(sort: (T, T) -> Bool) {
4545
heap = Heap(sort: sort)

Priority Queue/Tests/Tests.xcodeproj/project.pbxproj

+9-1
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@
8686
isa = PBXProject;
8787
attributes = {
8888
LastSwiftUpdateCheck = 0720;
89-
LastUpgradeCheck = 0720;
89+
LastUpgradeCheck = 0800;
9090
ORGANIZATIONNAME = "Swift Algorithm Club";
9191
TargetAttributes = {
9292
7B2BBC7F1C779D720067B71D = {
9393
CreatedOnToolsVersion = 7.2;
94+
LastSwiftMigration = 0800;
9495
};
9596
};
9697
};
@@ -149,8 +150,10 @@
149150
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
150151
CLANG_WARN_EMPTY_BODY = YES;
151152
CLANG_WARN_ENUM_CONVERSION = YES;
153+
CLANG_WARN_INFINITE_RECURSION = YES;
152154
CLANG_WARN_INT_CONVERSION = YES;
153155
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
156+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
154157
CLANG_WARN_UNREACHABLE_CODE = YES;
155158
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
156159
CODE_SIGN_IDENTITY = "-";
@@ -193,8 +196,10 @@
193196
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
194197
CLANG_WARN_EMPTY_BODY = YES;
195198
CLANG_WARN_ENUM_CONVERSION = YES;
199+
CLANG_WARN_INFINITE_RECURSION = YES;
196200
CLANG_WARN_INT_CONVERSION = YES;
197201
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
202+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
198203
CLANG_WARN_UNREACHABLE_CODE = YES;
199204
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
200205
CODE_SIGN_IDENTITY = "-";
@@ -213,6 +218,7 @@
213218
MACOSX_DEPLOYMENT_TARGET = 10.11;
214219
MTL_ENABLE_DEBUG_INFO = NO;
215220
SDKROOT = macosx;
221+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
216222
};
217223
name = Release;
218224
};
@@ -224,6 +230,7 @@
224230
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
225231
PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests;
226232
PRODUCT_NAME = "$(TARGET_NAME)";
233+
SWIFT_VERSION = 3.0;
227234
};
228235
name = Debug;
229236
};
@@ -235,6 +242,7 @@
235242
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
236243
PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests;
237244
PRODUCT_NAME = "$(TARGET_NAME)";
245+
SWIFT_VERSION = 3.0;
238246
};
239247
name = Release;
240248
};

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

+1-1
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)