From 8943b0925cc937b7e87c5d5b7f39e9ca00e750d1 Mon Sep 17 00:00:00 2001 From: Bruno Scheele Date: Thu, 4 Oct 2018 20:49:35 +0200 Subject: [PATCH 01/86] Update project with Xcode 10. --- .../Tests/Tests.xcodeproj/project.pbxproj | 24 +++++++++++++++---- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++++ .../xcshareddata/xcschemes/Tests.xcscheme | 2 +- 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 Bloom Filter/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Bloom Filter/Tests/Tests.xcodeproj/project.pbxproj b/Bloom Filter/Tests/Tests.xcodeproj/project.pbxproj index 6493fd153..f0649ba26 100644 --- a/Bloom Filter/Tests/Tests.xcodeproj/project.pbxproj +++ b/Bloom Filter/Tests/Tests.xcodeproj/project.pbxproj @@ -83,12 +83,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 1000; ORGANIZATIONNAME = "Swift Algorithm Club"; TargetAttributes = { 7B2BBC7F1C779D720067B71D = { CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 0800; + LastSwiftMigration = 1000; }; }; }; @@ -141,14 +141,22 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -188,14 +196,22 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -228,7 +244,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -240,7 +256,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/Bloom Filter/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Bloom Filter/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Bloom Filter/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Bloom Filter/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme b/Bloom Filter/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme index 14f27f777..afd69e6a7 100644 --- a/Bloom Filter/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme +++ b/Bloom Filter/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme @@ -1,6 +1,6 @@ Date: Thu, 4 Oct 2018 20:50:05 +0200 Subject: [PATCH 02/86] Remove use of deprecated `characters` property. --- Bloom Filter/Tests/BloomFilterTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Bloom Filter/Tests/BloomFilterTests.swift b/Bloom Filter/Tests/BloomFilterTests.swift index 30df702a7..d88ec0a31 100644 --- a/Bloom Filter/Tests/BloomFilterTests.swift +++ b/Bloom Filter/Tests/BloomFilterTests.swift @@ -6,7 +6,7 @@ import XCTest func djb2(_ x: String) -> Int { var hash = 5381 - for char in x.characters { + for char in x { hash = ((hash << 5) &+ hash) &+ char.hashValue } @@ -16,7 +16,7 @@ func djb2(_ x: String) -> Int { func sdbm(_ x: String) -> Int { var hash = 0 - for char in x.characters { + for char in x { hash = char.hashValue &+ (hash << 6) &+ (hash << 16) &- hash } From 6ef7a6e6ad07781320418d276a67eaa4e3d635d7 Mon Sep 17 00:00:00 2001 From: Bruno Scheele Date: Thu, 4 Oct 2018 20:57:46 +0200 Subject: [PATCH 03/86] Xcode 10 automated changes. --- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ Bloom Filter/BloomFilter.playground/timeline.xctimeline | 6 ------ 2 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 Bloom Filter/BloomFilter.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist delete mode 100644 Bloom Filter/BloomFilter.playground/timeline.xctimeline diff --git a/Bloom Filter/BloomFilter.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Bloom Filter/BloomFilter.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Bloom Filter/BloomFilter.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Bloom Filter/BloomFilter.playground/timeline.xctimeline b/Bloom Filter/BloomFilter.playground/timeline.xctimeline deleted file mode 100644 index bf468afec..000000000 --- a/Bloom Filter/BloomFilter.playground/timeline.xctimeline +++ /dev/null @@ -1,6 +0,0 @@ - - - - - From 4201fb4fc8bfefe4ab9651f5c393c55ddfd5f294 Mon Sep 17 00:00:00 2001 From: Bruno Scheele Date: Thu, 4 Oct 2018 20:58:26 +0200 Subject: [PATCH 04/86] Update for Swift 4.2. * Remove the top code snippet, as per instructions. * Remove use of deprecated `characters` property. --- Bloom Filter/BloomFilter.playground/Contents.swift | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Bloom Filter/BloomFilter.playground/Contents.swift b/Bloom Filter/BloomFilter.playground/Contents.swift index 9e4a89351..7a3719d57 100644 --- a/Bloom Filter/BloomFilter.playground/Contents.swift +++ b/Bloom Filter/BloomFilter.playground/Contents.swift @@ -1,8 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif + public class BloomFilter { fileprivate var array: [Bool] private var hashFunctions: [(T) -> Int] @@ -54,7 +51,7 @@ public class BloomFilter { func djb2(x: String) -> Int { var hash = 5381 - for char in x.characters { + for char in x { hash = ((hash << 5) &+ hash) &+ char.hashValue } return Int(hash) @@ -62,7 +59,7 @@ func djb2(x: String) -> Int { func sdbm(x: String) -> Int { var hash = 0 - for char in x.characters { + for char in x { hash = char.hashValue &+ (hash << 6) &+ (hash << 16) &- hash } return Int(hash) From 849309c5eb5d2ef29918940536cc1b011b665b3c Mon Sep 17 00:00:00 2001 From: Bruno Scheele Date: Thu, 4 Oct 2018 21:45:50 +0200 Subject: [PATCH 05/86] Add note about Hasher in README. * Adds a section about another Bloom filter approach, using only a single hashing function with Swift 4.2's `Hasher`. * Adds links to some more documentation and a blog post implementing the Bloom filter in this way. * Adds my name as updater. --- Bloom Filter/README.markdown | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Bloom Filter/README.markdown b/Bloom Filter/README.markdown index 3fff0a379..4364db857 100644 --- a/Bloom Filter/README.markdown +++ b/Bloom Filter/README.markdown @@ -100,4 +100,29 @@ public func query(_ value: T) -> Bool { If you're coming from another imperative language, you might notice the unusual syntax in the `exists` assignment. Swift makes use of functional paradigms when it makes code more consise and readable, and in this case `reduce` is a much more consise way to check if all the required bits are `true` than a `for` loop. -*Written for Swift Algorithm Club by Jamil Dhanani. Edited by Matthijs Hollemans.* +## Another approach + +Another approach to create different hashes of an element for use in the Bloom filter, is to use the same hash function for every iteration, but combine it with different random numbers. This can help, because finding good hashing functions is hard, but combining them is equally non-trivial. + +``` +hash("Hello world!") >> hash(987654321) // would flip bit 8 +hash("Hello world!") >> hash(123456789) // would flip bit 2 +``` + +Since Swift 4.2, `Hasher` is now included in the Standard library, which is designed to reduce multiple hashes to a single hash in an efficient manner. This makes combining the hashes trivial. + +``` +private func computeHashes(_ value: T) -> [Int] { + return randomSeeds.map() { seed in + let hasher = Hasher() + hasher.combine(seed) + hasher.combine(value) + let hashValue = hasher.finalize() + return abs(hashValue % array.count) + } +} +``` + +If you want to learn more about this approach, you can read about the [Hasher documentation](https://developer.apple.com/documentation/swift/hasher) or Soroush Khanlou's [Swift 4.2 Bloom filter](http://khanlou.com/2018/09/bloom-filters/) implementation. + +*Written for Swift Algorithm Club by Jamil Dhanani. Edited by Matthijs Hollemans. Updated by Bruno Scheele.* From a56b88370d49aaf0d5640ca59d955f61178108f8 Mon Sep 17 00:00:00 2001 From: KelCodesStuff Date: Thu, 4 Oct 2018 21:33:32 -0400 Subject: [PATCH 06/86] [Swift 4.2] Update Binary Search Tree --- .../Contents.swift | 5 -- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++ .../Tests/Tests.xcodeproj/project.pbxproj | 47 ++++++++++++++--- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++ .../xcshareddata/xcschemes/Tests.xcscheme | 2 +- .../Contents.swift | 5 -- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++ .../Sources/BinarySearch.swift | 52 ------------------- .../contents.xcworkspacedata | 7 --- 9 files changed, 64 insertions(+), 78 deletions(-) create mode 100644 Binary Search Tree/Solution 1/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Binary Search Tree/Solution 2/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist delete mode 100644 Binary Search/BinarySearch.playground/Sources/BinarySearch.swift delete mode 100644 Binary Search/BinarySearch.playground/playground.xcworkspace/contents.xcworkspacedata diff --git a/Binary Search Tree/Solution 1/BinarySearchTree.playground/Contents.swift b/Binary Search Tree/Solution 1/BinarySearchTree.playground/Contents.swift index 8c06ae9e1..ec9902283 100644 --- a/Binary Search Tree/Solution 1/BinarySearchTree.playground/Contents.swift +++ b/Binary Search Tree/Solution 1/BinarySearchTree.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - let tree = BinarySearchTree(value: 7) tree.insert(value: 2) tree.insert(value: 5) diff --git a/Binary Search Tree/Solution 1/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Binary Search Tree/Solution 1/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Binary Search Tree/Solution 1/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.pbxproj b/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.pbxproj index f4c3f65c7..ff594fff8 100644 --- a/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.pbxproj +++ b/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 51; objects = { /* Begin PBXBuildFile section */ @@ -83,17 +83,17 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0720; + LastUpgradeCheck = 1000; ORGANIZATIONNAME = "Swift Algorithm Club"; TargetAttributes = { 7B2BBC7F1C779D720067B71D = { CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 0820; + LastSwiftMigration = 1000; }; }; }; buildConfigurationList = 7B2BBC6C1C779D710067B71D /* Build configuration list for PBXProject "Tests" */; - compatibilityVersion = "Xcode 3.2"; + compatibilityVersion = "Xcode 10.0"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( @@ -141,13 +141,23 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; @@ -185,13 +195,23 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; @@ -210,6 +230,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; }; name = Release; }; @@ -218,10 +239,15 @@ buildSettings = { COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -230,10 +256,15 @@ buildSettings = { COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme b/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme index 8ef8d8581..afd69e6a7 100644 --- a/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme +++ b/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme @@ -1,6 +1,6 @@ =4.0) -print("Hello, Swift 4!") -#endif - // Each time you insert something, you get back a completely new tree. var tree = BinarySearchTree.leaf(7) tree = tree.insert(newValue: 2) diff --git a/Binary Search Tree/Solution 2/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Binary Search Tree/Solution 2/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Binary Search Tree/Solution 2/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Binary Search/BinarySearch.playground/Sources/BinarySearch.swift b/Binary Search/BinarySearch.playground/Sources/BinarySearch.swift deleted file mode 100644 index d6623e355..000000000 --- a/Binary Search/BinarySearch.playground/Sources/BinarySearch.swift +++ /dev/null @@ -1,52 +0,0 @@ -/** - Binary Search - - Recursively splits the array in half until the value is found. - - If there is more than one occurrence of the search key in the array, then - there is no guarantee which one it finds. - - Note: The array must be sorted! - **/ - -import Foundation - -// The recursive version of binary search. - -public func binarySearch(_ a: [T], key: T, range: Range) -> Int? { - if range.lowerBound >= range.upperBound { - return nil - } else { - let midIndex = range.lowerBound + (range.upperBound - range.lowerBound) / 2 - if a[midIndex] > key { - return binarySearch(a, key: key, range: range.lowerBound ..< midIndex) - } else if a[midIndex] < key { - return binarySearch(a, key: key, range: midIndex + 1 ..< range.upperBound) - } else { - return midIndex - } - } -} - -/** - The iterative version of binary search. - - Notice how similar these functions are. The difference is that this one - uses a while loop, while the other calls itself recursively. - **/ - -public func binarySearch(_ a: [T], key: T) -> Int? { - var lowerBound = 0 - var upperBound = a.count - while lowerBound < upperBound { - let midIndex = lowerBound + (upperBound - lowerBound) / 2 - if a[midIndex] == key { - return midIndex - } else if a[midIndex] < key { - lowerBound = midIndex + 1 - } else { - upperBound = midIndex - } - } - return nil -} diff --git a/Binary Search/BinarySearch.playground/playground.xcworkspace/contents.xcworkspacedata b/Binary Search/BinarySearch.playground/playground.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 919434a62..000000000 --- a/Binary Search/BinarySearch.playground/playground.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - From 54ac83543efd7bb47d1a976fcf9016ac618c3793 Mon Sep 17 00:00:00 2001 From: KelCodesStuff Date: Thu, 4 Oct 2018 21:38:01 -0400 Subject: [PATCH 07/86] [Swift 4.2] Update Binary Search Tree --- .../Contents.swift | 5 ++ .../xcshareddata/IDEWorkspaceChecks.plist | 8 ---- .../Tests/Tests.xcodeproj/project.pbxproj | 47 ++++--------------- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ---- .../xcshareddata/xcschemes/Tests.xcscheme | 2 +- .../Contents.swift | 5 ++ .../xcshareddata/IDEWorkspaceChecks.plist | 8 ---- 7 files changed, 19 insertions(+), 64 deletions(-) delete mode 100644 Binary Search Tree/Solution 1/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist delete mode 100644 Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist delete mode 100644 Binary Search Tree/Solution 2/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Binary Search Tree/Solution 1/BinarySearchTree.playground/Contents.swift b/Binary Search Tree/Solution 1/BinarySearchTree.playground/Contents.swift index ec9902283..8c06ae9e1 100644 --- a/Binary Search Tree/Solution 1/BinarySearchTree.playground/Contents.swift +++ b/Binary Search Tree/Solution 1/BinarySearchTree.playground/Contents.swift @@ -1,5 +1,10 @@ //: Playground - noun: a place where people can play +// last checked with Xcode 9.0b4 +#if swift(>=4.0) +print("Hello, Swift 4!") +#endif + let tree = BinarySearchTree(value: 7) tree.insert(value: 2) tree.insert(value: 5) diff --git a/Binary Search Tree/Solution 1/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Binary Search Tree/Solution 1/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d981003..000000000 --- a/Binary Search Tree/Solution 1/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - diff --git a/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.pbxproj b/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.pbxproj index ff594fff8..f4c3f65c7 100644 --- a/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.pbxproj +++ b/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 51; + objectVersion = 46; objects = { /* Begin PBXBuildFile section */ @@ -83,17 +83,17 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 1000; + LastUpgradeCheck = 0720; ORGANIZATIONNAME = "Swift Algorithm Club"; TargetAttributes = { 7B2BBC7F1C779D720067B71D = { CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 1000; + LastSwiftMigration = 0820; }; }; }; buildConfigurationList = 7B2BBC6C1C779D710067B71D /* Build configuration list for PBXProject "Tests" */; - compatibilityVersion = "Xcode 10.0"; + compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( @@ -141,23 +141,13 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; @@ -195,23 +185,13 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; @@ -230,7 +210,6 @@ MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; - SWIFT_COMPILATION_MODE = wholemodule; }; name = Release; }; @@ -239,15 +218,10 @@ buildSettings = { COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -256,15 +230,10 @@ buildSettings = { COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d981003..000000000 --- a/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - diff --git a/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme b/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme index afd69e6a7..8ef8d8581 100644 --- a/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme +++ b/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme @@ -1,6 +1,6 @@ =4.0) +print("Hello, Swift 4!") +#endif + // Each time you insert something, you get back a completely new tree. var tree = BinarySearchTree.leaf(7) tree = tree.insert(newValue: 2) diff --git a/Binary Search Tree/Solution 2/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Binary Search Tree/Solution 2/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d981003..000000000 --- a/Binary Search Tree/Solution 2/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - From e6a2aa77f23a515081d8bc806e46efc81d785321 Mon Sep 17 00:00:00 2001 From: KelCodesStuff Date: Thu, 4 Oct 2018 21:43:56 -0400 Subject: [PATCH 08/86] [Swift 4.2] Update Binary Search Tree --- .../Contents.swift | 5 --- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++ .../Tests/Tests.xcodeproj/project.pbxproj | 31 ++++++++++++++++--- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++ .../xcshareddata/xcschemes/Tests.xcscheme | 2 +- .../Contents.swift | 5 --- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++ 7 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 Binary Search Tree/Solution 1/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Binary Search Tree/Solution 2/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Binary Search Tree/Solution 1/BinarySearchTree.playground/Contents.swift b/Binary Search Tree/Solution 1/BinarySearchTree.playground/Contents.swift index 8c06ae9e1..ec9902283 100644 --- a/Binary Search Tree/Solution 1/BinarySearchTree.playground/Contents.swift +++ b/Binary Search Tree/Solution 1/BinarySearchTree.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - let tree = BinarySearchTree(value: 7) tree.insert(value: 2) tree.insert(value: 5) diff --git a/Binary Search Tree/Solution 1/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Binary Search Tree/Solution 1/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Binary Search Tree/Solution 1/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.pbxproj b/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.pbxproj index f4c3f65c7..d7c687e0c 100644 --- a/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.pbxproj +++ b/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.pbxproj @@ -83,12 +83,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0720; + LastUpgradeCheck = 1000; ORGANIZATIONNAME = "Swift Algorithm Club"; TargetAttributes = { 7B2BBC7F1C779D720067B71D = { CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 0820; + LastSwiftMigration = 1000; }; }; }; @@ -141,13 +141,23 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; @@ -185,13 +195,23 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; @@ -210,6 +230,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; }; name = Release; }; @@ -221,7 +242,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -233,7 +255,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme b/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme index 8ef8d8581..afd69e6a7 100644 --- a/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme +++ b/Binary Search Tree/Solution 1/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme @@ -1,6 +1,6 @@ =4.0) -print("Hello, Swift 4!") -#endif - // Each time you insert something, you get back a completely new tree. var tree = BinarySearchTree.leaf(7) tree = tree.insert(newValue: 2) diff --git a/Binary Search Tree/Solution 2/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Binary Search Tree/Solution 2/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Binary Search Tree/Solution 2/BinarySearchTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From 01ba34cc5084c7f70beb3955d71918f75fb30bd0 Mon Sep 17 00:00:00 2001 From: KelCodesStuff Date: Thu, 4 Oct 2018 22:17:58 -0400 Subject: [PATCH 09/86] [Swift 4.2] Merge Sort --- Merge Sort/MergeSort.playground/Contents.swift | 5 ----- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 Merge Sort/MergeSort.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Merge Sort/MergeSort.playground/Contents.swift b/Merge Sort/MergeSort.playground/Contents.swift index b05332bfe..ca1347890 100644 --- a/Merge Sort/MergeSort.playground/Contents.swift +++ b/Merge Sort/MergeSort.playground/Contents.swift @@ -1,10 +1,5 @@ /* Top-down recursive version */ -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - func mergeSort(_ array: [T]) -> [T] { guard array.count > 1 else { return array } let middleIndex = array.count / 2 diff --git a/Merge Sort/MergeSort.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Merge Sort/MergeSort.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Merge Sort/MergeSort.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From 3f0bdc6ec0009bf08251458a04b11631d13cb7c7 Mon Sep 17 00:00:00 2001 From: danielchick Date: Thu, 4 Oct 2018 22:44:53 -0500 Subject: [PATCH 10/86] [Swift 4.2] Update Tree --- Tree/Tree.playground/Contents.swift | 4 ++-- Tree/Tree.playground/contents.xcplayground | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tree/Tree.playground/Contents.swift b/Tree/Tree.playground/Contents.swift index 49cf41054..06f992fa8 100644 --- a/Tree/Tree.playground/Contents.swift +++ b/Tree/Tree.playground/Contents.swift @@ -1,8 +1,8 @@ //: Playground - noun: a place where people can play // last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") +#if swift(>=4.2) +print("Hello, Swift 4.2!") #endif let tree = TreeNode(value: "beverages") diff --git a/Tree/Tree.playground/contents.xcplayground b/Tree/Tree.playground/contents.xcplayground index 06828af92..69d154d1e 100644 --- a/Tree/Tree.playground/contents.xcplayground +++ b/Tree/Tree.playground/contents.xcplayground @@ -1,4 +1,4 @@ - + \ No newline at end of file From 6ab163e4431ba09a6870b4b101dc536cffcf759d Mon Sep 17 00:00:00 2001 From: Bruno Scheele Date: Fri, 5 Oct 2018 09:34:07 +0200 Subject: [PATCH 11/86] Update to Xcode 10. --- Bucket Sort/Tests/Tests.xcodeproj/project.pbxproj | 6 +++++- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ .../Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme | 4 +--- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 Bucket Sort/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Bucket Sort/Tests/Tests.xcodeproj/project.pbxproj b/Bucket Sort/Tests/Tests.xcodeproj/project.pbxproj index 84a305784..6df507720 100644 --- a/Bucket Sort/Tests/Tests.xcodeproj/project.pbxproj +++ b/Bucket Sort/Tests/Tests.xcodeproj/project.pbxproj @@ -83,7 +83,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1000; ORGANIZATIONNAME = "Swift Algorithm Club"; TargetAttributes = { 7B2BBC7F1C779D720067B71D = { @@ -145,12 +145,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -197,12 +199,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; diff --git a/Bucket Sort/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Bucket Sort/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Bucket Sort/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Bucket Sort/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme b/Bucket Sort/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme index 538a6f4fa..afd69e6a7 100644 --- a/Bucket Sort/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme +++ b/Bucket Sort/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme @@ -1,6 +1,6 @@ Date: Fri, 5 Oct 2018 09:49:56 +0200 Subject: [PATCH 12/86] 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. --- Bucket Sort/BucketSort.swift | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/Bucket Sort/BucketSort.swift b/Bucket Sort/BucketSort.swift index 108073288..4c2abd372 100644 --- a/Bucket Sort/BucketSort.swift +++ b/Bucket Sort/BucketSort.swift @@ -20,31 +20,6 @@ // // -import Foundation -// FIXME: comparison operators with optionals were removed from the Swift Standard Libary. -// Consider refactoring the code to use the non-optional operators. -fileprivate func < (lhs: T?, rhs: T?) -> Bool { - switch (lhs, rhs) { - case let (l?, r?): - return l < r - case (nil, _?): - return true - default: - return false - } -} - -// FIXME: comparison operators with optionals were removed from the Swift Standard Libary. -// Consider refactoring the code to use the non-optional operators. -fileprivate func >= (lhs: T?, rhs: T?) -> Bool { - switch (lhs, rhs) { - case let (l?, r?): - return l >= r - default: - return !(lhs < rhs) - } -} - ////////////////////////////////////// // MARK: Main algorithm ////////////////////////////////////// @@ -87,7 +62,11 @@ private func enoughSpaceInBuckets(_ buckets: [Bucket], elements: [T]) -> B let maximumValue = elements.max()?.toInt() let totalCapacity = buckets.count * (buckets.first?.capacity)! - return totalCapacity >= maximumValue + guard let max = maximumValue else { + return false + } + + return totalCapacity >= max } ////////////////////////////////////// From 8f2bf19304b379d60551359f913080e22b8d7ed3 Mon Sep 17 00:00:00 2001 From: Bruno Scheele Date: Fri, 5 Oct 2018 09:55:40 +0200 Subject: [PATCH 13/86] Change playground as well. --- .../Sources/BucketSort.swift | 31 +++---------------- .../contents.xcplayground | 2 +- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++ 3 files changed, 14 insertions(+), 27 deletions(-) create mode 100644 Bucket Sort/BucketSort.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Bucket Sort/BucketSort.playground/Sources/BucketSort.swift b/Bucket Sort/BucketSort.playground/Sources/BucketSort.swift index bafd216fa..64408eca4 100644 --- a/Bucket Sort/BucketSort.playground/Sources/BucketSort.swift +++ b/Bucket Sort/BucketSort.playground/Sources/BucketSort.swift @@ -20,31 +20,6 @@ // // -import Foundation -// FIXME: comparison operators with optionals were removed from the Swift Standard Libary. -// Consider refactoring the code to use the non-optional operators. -fileprivate func < (lhs: T?, rhs: T?) -> Bool { - switch (lhs, rhs) { - case let (l?, r?): - return l < r - case (nil, _?): - return true - default: - return false - } -} - -// FIXME: comparison operators with optionals were removed from the Swift Standard Libary. -// Consider refactoring the code to use the non-optional operators. -fileprivate func >= (lhs: T?, rhs: T?) -> Bool { - switch (lhs, rhs) { - case let (l?, r?): - return l >= r - default: - return !(lhs < rhs) - } -} - ////////////////////////////////////// // MARK: Main algorithm ////////////////////////////////////// @@ -87,7 +62,11 @@ private func enoughSpaceInBuckets(_ buckets: [Bucket], elements: [T]) -> B let maximumValue = elements.max()?.toInt() let totalCapacity = buckets.count * (buckets.first?.capacity)! - return totalCapacity >= maximumValue + guard let max = maximumValue else { + return false + } + + return totalCapacity >= max } ////////////////////////////////////// diff --git a/Bucket Sort/BucketSort.playground/contents.xcplayground b/Bucket Sort/BucketSort.playground/contents.xcplayground index 5da2641c9..9f5f2f40c 100644 --- a/Bucket Sort/BucketSort.playground/contents.xcplayground +++ b/Bucket Sort/BucketSort.playground/contents.xcplayground @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/Bucket Sort/BucketSort.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Bucket Sort/BucketSort.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Bucket Sort/BucketSort.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From f28973201916ac83c3b95f4115215a09715d22b7 Mon Sep 17 00:00:00 2001 From: Bruno Scheele Date: Fri, 5 Oct 2018 09:58:24 +0200 Subject: [PATCH 14/86] Add credit to README. --- Bucket Sort/README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Bucket Sort/README.markdown b/Bucket Sort/README.markdown index f572fc9a1..f2708d71e 100644 --- a/Bucket Sort/README.markdown +++ b/Bucket Sort/README.markdown @@ -256,4 +256,4 @@ The following are some of the variation to the general [Bucket Sort](https://en. - [Postman Sort](https://en.wikipedia.org/wiki/Bucket_sort#Postman.27s_sort) - [Shuffle Sort](https://en.wikipedia.org/wiki/Bucket_sort#Shuffle_sort) -*Written for Swift Algorithm Club by Barbara Rodeker. Images from Wikipedia.* +*Written for Swift Algorithm Club by Barbara Rodeker. Images from Wikipedia. Updated by Bruno Scheele.* From 184786db68a17e40cfe2e4de6f7f212a84db42d4 Mon Sep 17 00:00:00 2001 From: KelCodesStuff Date: Fri, 5 Oct 2018 21:27:02 -0400 Subject: [PATCH 15/86] [Swift 4.2] Threaded Binary Tree --- .../ThreadedBinaryTree.playground/Contents.swift | 5 ----- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 Threaded Binary Tree/ThreadedBinaryTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Threaded Binary Tree/ThreadedBinaryTree.playground/Contents.swift b/Threaded Binary Tree/ThreadedBinaryTree.playground/Contents.swift index 4ce9d8157..ece1966e0 100644 --- a/Threaded Binary Tree/ThreadedBinaryTree.playground/Contents.swift +++ b/Threaded Binary Tree/ThreadedBinaryTree.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - // Simple little debug function to make testing output pretty func check(_ tree: ThreadedBinaryTree?) { if let tree = tree { diff --git a/Threaded Binary Tree/ThreadedBinaryTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Threaded Binary Tree/ThreadedBinaryTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Threaded Binary Tree/ThreadedBinaryTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From cafba43a1c38bad9f62400e42ef46b9f51c60df3 Mon Sep 17 00:00:00 2001 From: Aleph Retamal Date: Sat, 6 Oct 2018 18:11:50 +1000 Subject: [PATCH 16/86] [Swift 4.2] Update K-Means --- K-Means/KMeans.swift | 2 +- K-Means/Tests/KMeansTests.swift | 7 ------ K-Means/Tests/Tests.xcodeproj/project.pbxproj | 24 +++++++++++++++---- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++++ .../xcshareddata/xcschemes/Tests.xcscheme | 2 +- 5 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 K-Means/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/K-Means/KMeans.swift b/K-Means/KMeans.swift index 4a89a3fae..bccc6efd3 100644 --- a/K-Means/KMeans.swift +++ b/K-Means/KMeans.swift @@ -12,7 +12,7 @@ class KMeans { } private func indexOfNearestCenter(_ x: Vector, centers: [Vector]) -> Int { - var nearestDist = DBL_MAX + var nearestDist = Double.greatestFiniteMagnitude var minIndex = 0 for (idx, center) in centers.enumerated() { diff --git a/K-Means/Tests/KMeansTests.swift b/K-Means/Tests/KMeansTests.swift index e6f4b08a1..7e0c93004 100644 --- a/K-Means/Tests/KMeansTests.swift +++ b/K-Means/Tests/KMeansTests.swift @@ -10,13 +10,6 @@ import Foundation import XCTest class KMeansTests: XCTestCase { - func testSwift4() { - // last checked with Xcode 9.0b4 - #if swift(>=4.0) - print("Hello, Swift 4!") - #endif - } - func genPoints(_ numPoints: Int, numDimensions: Int) -> [Vector] { var points = [Vector]() for _ in 0.. + + + + IDEDidComputeMac32BitWarning + + + diff --git a/K-Means/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme b/K-Means/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme index 2b401e86e..73ba8f37d 100644 --- a/K-Means/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme +++ b/K-Means/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme @@ -1,6 +1,6 @@ Date: Sat, 6 Oct 2018 19:28:22 +1000 Subject: [PATCH 17/86] [Swift 4.2] Update Egg Drop Problem --- Egg Drop Problem/EggDrop.playground/Contents.swift | 4 ---- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ .../xcshareddata/WorkspaceSettings.xcsettings | 5 +++++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 Egg Drop Problem/EggDrop.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Egg Drop Problem/EggDrop.playground/playground.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/Egg Drop Problem/EggDrop.playground/Contents.swift b/Egg Drop Problem/EggDrop.playground/Contents.swift index 0b707da98..decaacdca 100644 --- a/Egg Drop Problem/EggDrop.playground/Contents.swift +++ b/Egg Drop Problem/EggDrop.playground/Contents.swift @@ -1,7 +1,3 @@ -#if swift(>=4.0) - print("Hello, Swift 4!") -#endif - drop(numberOfEggs: 2, numberOfFloors: 2) //expected answer: 2 drop(numberOfEggs: 2, numberOfFloors: 4) //expected answer: 3 drop(numberOfEggs: 2, numberOfFloors: 6) //expected answer: 3 diff --git a/Egg Drop Problem/EggDrop.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Egg Drop Problem/EggDrop.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Egg Drop Problem/EggDrop.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Egg Drop Problem/EggDrop.playground/playground.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/Egg Drop Problem/EggDrop.playground/playground.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 000000000..0c67376eb --- /dev/null +++ b/Egg Drop Problem/EggDrop.playground/playground.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,5 @@ + + + + + From 2d60bb78c249085c47714474d27d97297a09fa2f Mon Sep 17 00:00:00 2001 From: askari01 Date: Sat, 6 Oct 2018 23:02:19 +0500 Subject: [PATCH 18/86] 2 sum problem with swift 4.2 --- Two-Sum Problem/Solution 1/2Sum.playground/Contents.swift | 5 +---- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ Two-Sum Problem/Solution 2/2Sum.playground/Contents.swift | 5 +---- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 4 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 Two-Sum Problem/Solution 1/2Sum.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Two-Sum Problem/Solution 2/2Sum.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Two-Sum Problem/Solution 1/2Sum.playground/Contents.swift b/Two-Sum Problem/Solution 1/2Sum.playground/Contents.swift index 26bfae449..00a39b04a 100644 --- a/Two-Sum Problem/Solution 1/2Sum.playground/Contents.swift +++ b/Two-Sum Problem/Solution 1/2Sum.playground/Contents.swift @@ -1,8 +1,5 @@ //: Two Sum -// Last checked with: Version 9.0 (9A235) -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif +// Last checked with: Version 10.0 (10A255) func twoSum(_ nums: [Int], target: Int) -> (Int, Int)? { var dict = [Int: Int]() diff --git a/Two-Sum Problem/Solution 1/2Sum.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Two-Sum Problem/Solution 1/2Sum.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Two-Sum Problem/Solution 1/2Sum.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Two-Sum Problem/Solution 2/2Sum.playground/Contents.swift b/Two-Sum Problem/Solution 2/2Sum.playground/Contents.swift index 4cb3d9283..469c15b5f 100644 --- a/Two-Sum Problem/Solution 2/2Sum.playground/Contents.swift +++ b/Two-Sum Problem/Solution 2/2Sum.playground/Contents.swift @@ -1,8 +1,5 @@ //: Playground - noun: a place where people can play -// Last checked with: Version 9.0 beta 4 (9M189t) -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif +// Last checked with: Version 10.0 (10A255) func twoSumProblem(_ a: [Int], k: Int) -> ((Int, Int))? { var i = 0 diff --git a/Two-Sum Problem/Solution 2/2Sum.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Two-Sum Problem/Solution 2/2Sum.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Two-Sum Problem/Solution 2/2Sum.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From f0ce485316036d977470c7d38e9a1959e8a60f08 Mon Sep 17 00:00:00 2001 From: askari01 Date: Sat, 6 Oct 2018 23:08:23 +0500 Subject: [PATCH 19/86] updated readme for 2 sum problem with swift 4.2 --- Two-Sum Problem/README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Two-Sum Problem/README.markdown b/Two-Sum Problem/README.markdown index 4d8ffcd95..bbd033343 100644 --- a/Two-Sum Problem/README.markdown +++ b/Two-Sum Problem/README.markdown @@ -168,4 +168,4 @@ I'm quite enamored by this little algorithm. It shows that with some basic prepr * [3Sum / 4Sum](https://github.com/raywenderlich/swift-algorithm-club/tree/master/3Sum%20and%204Sum) -*Written for Swift Algorithm Club by Matthijs Hollemans and Daniel Speiser* +*Written for Swift Algorithm Club by Matthijs Hollemans and Daniel Speiser updated to swift 4.2 by Farrukh Askari* From 34526e97eb792f62a942c8379968f0494ae084c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Afonso=20Gra=C3=A7a?= Date: Mon, 8 Oct 2018 20:31:20 +1100 Subject: [PATCH 20/86] [Swift 4.2] Update Fizz Buzz There was no need to update the source code, simply removed the code snippet. --- Fizz Buzz/FizzBuzz.playground/Contents.swift | 5 +---- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 Fizz Buzz/FizzBuzz.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Fizz Buzz/FizzBuzz.playground/Contents.swift b/Fizz Buzz/FizzBuzz.playground/Contents.swift index 37acdab61..ae966bbcc 100644 --- a/Fizz Buzz/FizzBuzz.playground/Contents.swift +++ b/Fizz Buzz/FizzBuzz.playground/Contents.swift @@ -1,7 +1,4 @@ -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif +// last checked with Xcode 10.0 (10A255) func fizzBuzz(_ numberOfTurns: Int) { for i in 1...numberOfTurns { diff --git a/Fizz Buzz/FizzBuzz.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Fizz Buzz/FizzBuzz.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Fizz Buzz/FizzBuzz.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From 409e85fdc8968230758ef703804f51956dc524a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=BD=D0=BA=D0=BE=D0=B2=D0=B0=20=D0=9C=D0=B0?= =?UTF-8?q?=D1=80=D0=B8=D1=8F=20=D0=92=D0=B8=D1=82=D0=B0=D0=BB=D1=8C=D0=B5?= =?UTF-8?q?=D0=B2=D0=BD=D0=B0?= Date: Mon, 8 Oct 2018 21:49:03 +0700 Subject: [PATCH 21/86] [Swift 4.2] Update Convex Hull --- .../Convex Hull.xcodeproj/project.pbxproj | 26 +++++++++++++++---- .../xcshareddata/xcschemes/Tests.xcscheme | 4 +-- .../AppIcon.appiconset/Contents.json | 5 ++++ Convex Hull/Convex Hull/View.swift | 4 +-- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Convex Hull/Convex Hull.xcodeproj/project.pbxproj b/Convex Hull/Convex Hull.xcodeproj/project.pbxproj index c11cbf4d6..27ca4eb25 100644 --- a/Convex Hull/Convex Hull.xcodeproj/project.pbxproj +++ b/Convex Hull/Convex Hull.xcodeproj/project.pbxproj @@ -139,7 +139,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0900; - LastUpgradeCheck = 0820; + LastUpgradeCheck = 1000; ORGANIZATIONNAME = Workmoose; TargetAttributes = { 1CB6142C1F89456C00A14493 = { @@ -254,7 +254,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.mnespor.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Convex Hull.app/Convex Hull"; }; @@ -281,7 +281,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.mnespor.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Convex Hull.app/Convex Hull"; }; @@ -296,15 +296,23 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -346,15 +354,23 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -389,7 +405,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "workmoose.Convex-Hull"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -402,7 +418,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "workmoose.Convex-Hull"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/Convex Hull/Convex Hull.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme b/Convex Hull/Convex Hull.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme index 1f93a0c4f..8f04a0f51 100644 --- a/Convex Hull/Convex Hull.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme +++ b/Convex Hull/Convex Hull.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme @@ -1,6 +1,6 @@ Date: Wed, 10 Oct 2018 22:39:38 +0300 Subject: [PATCH 22/86] [Swift 4.2] Update Boyer-Moore-Horspool --- .../BoyerMooreHorspool.playground/Contents.swift | 6 +++--- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ .../BoyerMooreHorspool.playground/timeline.xctimeline | 6 +++--- Boyer-Moore-Horspool/BoyerMooreHorspool.swift | 6 +++--- 4 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 Boyer-Moore-Horspool/BoyerMooreHorspool.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift index e88a1b93d..5817cc41f 100644 --- a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift +++ b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift @@ -16,13 +16,13 @@ extension String { func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Index? { // Cache the length of the search pattern because we're going to // use it a few times and it's expensive to calculate. - let patternLength = pattern.characters.count - guard patternLength > 0, patternLength <= characters.count else { return nil } + let patternLength = pattern.count + guard patternLength > 0, patternLength <= count else { return nil } // Make the skip table. This table determines how far we skip ahead // when a character from the pattern is found. var skipTable = [Character: Int]() - for (i, c) in pattern.characters.enumerated() { + for (i, c) in pattern.enumerated() { skipTable[c] = patternLength - i - 1 } diff --git a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/timeline.xctimeline b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/timeline.xctimeline index 89bc76f90..2688d72c1 100644 --- a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/timeline.xctimeline +++ b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/timeline.xctimeline @@ -3,17 +3,17 @@ version = "3.0"> diff --git a/Boyer-Moore-Horspool/BoyerMooreHorspool.swift b/Boyer-Moore-Horspool/BoyerMooreHorspool.swift index af8aea9d9..dbd738740 100644 --- a/Boyer-Moore-Horspool/BoyerMooreHorspool.swift +++ b/Boyer-Moore-Horspool/BoyerMooreHorspool.swift @@ -9,13 +9,13 @@ extension String { func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Index? { // Cache the length of the search pattern because we're going to // use it a few times and it's expensive to calculate. - let patternLength = pattern.characters.count - guard patternLength > 0, patternLength <= characters.count else { return nil } + let patternLength = pattern.count + guard patternLength > 0, patternLength <= count else { return nil } // Make the skip table. This table determines how far we skip ahead // when a character from the pattern is found. var skipTable = [Character: Int]() - for (i, c) in pattern.characters.enumerated() { + for (i, c) in pattern.enumerated() { skipTable[c] = patternLength - i - 1 } From 8e6c983cd0c5ae26a68531bb54521b85f3926120 Mon Sep 17 00:00:00 2001 From: Varun Date: Thu, 11 Oct 2018 13:41:40 +0530 Subject: [PATCH 23/86] updated LinkedList.playground to swift 4.2 --- Linked List/LinkedList.playground/Contents.swift | 4 ---- Linked List/LinkedList.playground/contents.xcplayground | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Linked List/LinkedList.playground/Contents.swift b/Linked List/LinkedList.playground/Contents.swift index cfa3a8b45..894b2d37f 100644 --- a/Linked List/LinkedList.playground/Contents.swift +++ b/Linked List/LinkedList.playground/Contents.swift @@ -3,10 +3,6 @@ // For best results, don't forget to select "Show Rendered Markup" from XCode's "Editor" menu //: Linked List Class Declaration: -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif public final class LinkedList { diff --git a/Linked List/LinkedList.playground/contents.xcplayground b/Linked List/LinkedList.playground/contents.xcplayground index 3de2b51ba..5e28f2dd0 100644 --- a/Linked List/LinkedList.playground/contents.xcplayground +++ b/Linked List/LinkedList.playground/contents.xcplayground @@ -1,4 +1,4 @@ - + \ No newline at end of file From 3f0ee826265621d22205316a3f52f22d7e5ee39f Mon Sep 17 00:00:00 2001 From: Bruno Scheele Date: Thu, 11 Oct 2018 14:17:34 +0200 Subject: [PATCH 24/86] Update to Swift 4.2. Also removed unused Tests group from project. --- .../project.pbxproj | 22 ++++++++----------- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++++ 2 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 DiningPhilosophers/DiningPhilosophers.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/DiningPhilosophers/DiningPhilosophers.xcodeproj/project.pbxproj b/DiningPhilosophers/DiningPhilosophers.xcodeproj/project.pbxproj index ecb060026..97f3c4847 100755 --- a/DiningPhilosophers/DiningPhilosophers.xcodeproj/project.pbxproj +++ b/DiningPhilosophers/DiningPhilosophers.xcodeproj/project.pbxproj @@ -27,13 +27,6 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - OBJ_10 /* Tests */ = { - isa = PBXGroup; - children = ( - ); - path = Tests; - sourceTree = ""; - }; OBJ_11 /* Products */ = { isa = PBXGroup; children = ( @@ -42,15 +35,13 @@ name = Products; sourceTree = BUILT_PRODUCTS_DIR; }; - OBJ_5 /* */ = { + OBJ_5 = { isa = PBXGroup; children = ( OBJ_6 /* Package.swift */, OBJ_7 /* Sources */, - OBJ_10 /* Tests */, OBJ_11 /* Products */, ); - name = ""; sourceTree = ""; }; OBJ_7 /* Sources */ = { @@ -96,6 +87,11 @@ isa = PBXProject; attributes = { LastUpgradeCheck = 9999; + TargetAttributes = { + OBJ_13 = { + LastSwiftMigration = 1000; + }; + }; }; buildConfigurationList = OBJ_2 /* Build configuration list for PBXProject "DiningPhilosophers" */; compatibilityVersion = "Xcode 3.2"; @@ -104,7 +100,7 @@ knownRegions = ( en, ); - mainGroup = OBJ_5 /* */; + mainGroup = OBJ_5; productRefGroup = OBJ_11 /* Products */; projectDirPath = ""; projectRoot = ""; @@ -139,7 +135,7 @@ SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE; SWIFT_FORCE_DYNAMIC_LINK_STDLIB = YES; SWIFT_FORCE_STATIC_LINK_STDLIB = NO; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGET_NAME = DiningPhilosophers; }; name = Debug; @@ -157,7 +153,7 @@ SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE; SWIFT_FORCE_DYNAMIC_LINK_STDLIB = YES; SWIFT_FORCE_STATIC_LINK_STDLIB = NO; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGET_NAME = DiningPhilosophers; }; name = Release; diff --git a/DiningPhilosophers/DiningPhilosophers.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/DiningPhilosophers/DiningPhilosophers.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/DiningPhilosophers/DiningPhilosophers.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From 6c48b3d493b4e6f023b006871f58fbe485db96b1 Mon Sep 17 00:00:00 2001 From: Bruno Scheele Date: Thu, 11 Oct 2018 14:18:45 +0200 Subject: [PATCH 25/86] Add README.md to project. This makes it easier to read along with the code. --- DiningPhilosophers/DiningPhilosophers.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DiningPhilosophers/DiningPhilosophers.xcodeproj/project.pbxproj b/DiningPhilosophers/DiningPhilosophers.xcodeproj/project.pbxproj index 97f3c4847..7699219de 100755 --- a/DiningPhilosophers/DiningPhilosophers.xcodeproj/project.pbxproj +++ b/DiningPhilosophers/DiningPhilosophers.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 232D7939216F76F700831A74 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; OBJ_12 /* DiningPhilosophers */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; path = DiningPhilosophers; sourceTree = BUILT_PRODUCTS_DIR; }; OBJ_6 /* Package.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; OBJ_9 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; @@ -38,6 +39,7 @@ OBJ_5 = { isa = PBXGroup; children = ( + 232D7939216F76F700831A74 /* README.md */, OBJ_6 /* Package.swift */, OBJ_7 /* Sources */, OBJ_11 /* Products */, From f2c04f7ac0ed2634221eca58ed303e3a3b239cd9 Mon Sep 17 00:00:00 2001 From: Bruno Scheele Date: Thu, 11 Oct 2018 14:18:54 +0200 Subject: [PATCH 26/86] Add credit to README.md. --- DiningPhilosophers/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DiningPhilosophers/README.md b/DiningPhilosophers/README.md index cd9d86154..aed9dfe59 100755 --- a/DiningPhilosophers/README.md +++ b/DiningPhilosophers/README.md @@ -57,3 +57,4 @@ A background DispatchQueue is then used to let any Philosopher run asyncrounosly Dining Philosophers on Wikipedia https://en.wikipedia.org/wiki/Dining_philosophers_problem Written for Swift Algorithm Club by Jacopo Mangiavacchi +Swift 4.2 check by Bruno Scheele From eeb116e4073a0b1a0a9d13701bbe27d29e1ec6bb Mon Sep 17 00:00:00 2001 From: Bruno Scheele Date: Thu, 11 Oct 2018 14:26:17 +0200 Subject: [PATCH 27/86] Update to Swift 4.2. --- Red-Black Tree/RedBlackTree.playground/Contents.swift | 5 ----- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 Red-Black Tree/RedBlackTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Red-Black Tree/RedBlackTree.playground/Contents.swift b/Red-Black Tree/RedBlackTree.playground/Contents.swift index f14f18e58..d1133bc98 100644 --- a/Red-Black Tree/RedBlackTree.playground/Contents.swift +++ b/Red-Black Tree/RedBlackTree.playground/Contents.swift @@ -2,11 +2,6 @@ // Test for the RedBlackTree implementation provided in the Source folder of this Playground import Foundation -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - let redBlackTree = RedBlackTree() let randomMax = Double(0x10000000) diff --git a/Red-Black Tree/RedBlackTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Red-Black Tree/RedBlackTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Red-Black Tree/RedBlackTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From af9a6564f87da3390d9c0287995ba213f47c94ad Mon Sep 17 00:00:00 2001 From: Bruno Scheele Date: Thu, 11 Oct 2018 14:26:34 +0200 Subject: [PATCH 28/86] Add credit to README.md. --- Red-Black Tree/README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Red-Black Tree/README.markdown b/Red-Black Tree/README.markdown index 74fffa415..fd6c4db18 100644 --- a/Red-Black Tree/README.markdown +++ b/Red-Black Tree/README.markdown @@ -186,4 +186,4 @@ The overall runtime of delete is O(log n). ## Resources: [CLRS] T. Cormen, C. Leiserson, R. Rivest, and C. Stein. "Introduction to Algorithms", Third Edition. 2009 -*Written for Swift Algorithm Club by Ute Schiehlen. Updated from Jaap Wijnen and Ashwin Raghuraman's contributions.* +*Written for Swift Algorithm Club by Ute Schiehlen. Updated from Jaap Wijnen and Ashwin Raghuraman's contributions. Swift 4.2 check by Bruno Scheele.* From d3d382f1d2f76c91a14a9b61b02375f7c6388265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BA=D0=B0=D1=82=D0=B5=D1=80=D0=B8=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=91=D0=B0=D1=82=D0=B5=D0=B5=D0=B2=D0=B0?= Date: Fri, 12 Oct 2018 23:06:22 +0300 Subject: [PATCH 29/86] Fix HarversineDistance pi parameter in "Converts from degrees to radians" --- HaversineDistance/HaversineDistance.playground/Contents.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HaversineDistance/HaversineDistance.playground/Contents.swift b/HaversineDistance/HaversineDistance.playground/Contents.swift index 5b3f591d6..7aa686645 100644 --- a/HaversineDistance/HaversineDistance.playground/Contents.swift +++ b/HaversineDistance/HaversineDistance.playground/Contents.swift @@ -16,7 +16,7 @@ func haversineDinstance(la1: Double, lo1: Double, la2: Double, lo2: Double, radi // Converts from degrees to radians let dToR = { (angle: Double) -> Double in - return (angle / 360) * 2 * M_PI + return (angle / 360) * 2 * .pi } let lat1 = dToR(la1) From acb21c32df8cc6c2ba8c153497902c24a661fff4 Mon Sep 17 00:00:00 2001 From: Nick Thompson Date: Fri, 12 Oct 2018 17:18:55 -0400 Subject: [PATCH 30/86] Updated MST to Swift 4.2 --- .../MinimumSpanningTree.playground/Contents.swift | 5 ----- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 Minimum Spanning Tree/MinimumSpanningTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Minimum Spanning Tree/MinimumSpanningTree.playground/Contents.swift b/Minimum Spanning Tree/MinimumSpanningTree.playground/Contents.swift index c4f0a811b..7e3532429 100644 --- a/Minimum Spanning Tree/MinimumSpanningTree.playground/Contents.swift +++ b/Minimum Spanning Tree/MinimumSpanningTree.playground/Contents.swift @@ -3,11 +3,6 @@ Kruskal's and Prim's algorithms. */ -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - func minimumSpanningTreeKruskal(graph: Graph) -> (cost: Int, tree: Graph) { var cost: Int = 0 var tree = Graph() diff --git a/Minimum Spanning Tree/MinimumSpanningTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Minimum Spanning Tree/MinimumSpanningTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Minimum Spanning Tree/MinimumSpanningTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From e0c6676601b6de0b093d3a171bf7497c73947522 Mon Sep 17 00:00:00 2001 From: Nick Thompson Date: Fri, 12 Oct 2018 17:37:17 -0400 Subject: [PATCH 31/86] Updated MST (Unweighted) to Swift 4.2 --- .../Contents.swift | 5 ----- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Pages/Minimum spanning tree example.xcplaygroundpage/Contents.swift b/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Pages/Minimum spanning tree example.xcplaygroundpage/Contents.swift index 65aa9fbc4..8ad04379c 100644 --- a/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Pages/Minimum spanning tree example.xcplaygroundpage/Contents.swift +++ b/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Pages/Minimum spanning tree example.xcplaygroundpage/Contents.swift @@ -1,8 +1,3 @@ -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - func breadthFirstSearchMinimumSpanningTree(_ graph: Graph, source: Node) -> Graph { let minimumSpanningTree = graph.duplicate() diff --git a/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From 45cca894960b5aab35f8e675c1e2066025e7df91 Mon Sep 17 00:00:00 2001 From: Nick Thompson Date: Fri, 12 Oct 2018 17:40:24 -0400 Subject: [PATCH 32/86] Updated MST (Unweighted) tests to Swift 4.2 --- .../Tests/Tests.xcodeproj/project.pbxproj | 31 ++++++++++++++++--- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++ .../xcshareddata/xcschemes/Tests.xcscheme | 2 +- 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 Minimum Spanning Tree (Unweighted)/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Minimum Spanning Tree (Unweighted)/Tests/Tests.xcodeproj/project.pbxproj b/Minimum Spanning Tree (Unweighted)/Tests/Tests.xcodeproj/project.pbxproj index a066b7a71..afb3b8acb 100644 --- a/Minimum Spanning Tree (Unweighted)/Tests/Tests.xcodeproj/project.pbxproj +++ b/Minimum Spanning Tree (Unweighted)/Tests/Tests.xcodeproj/project.pbxproj @@ -89,12 +89,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0720; + LastUpgradeCheck = 1000; ORGANIZATIONNAME = "Swift Algorithm Club"; TargetAttributes = { 7B2BBC7F1C779D720067B71D = { CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 0820; + LastSwiftMigration = 1000; }; }; }; @@ -149,13 +149,23 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; @@ -193,13 +203,23 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; @@ -218,6 +238,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; }; name = Release; }; @@ -231,7 +252,8 @@ PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -244,7 +266,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/Minimum Spanning Tree (Unweighted)/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Minimum Spanning Tree (Unweighted)/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Minimum Spanning Tree (Unweighted)/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Minimum Spanning Tree (Unweighted)/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme b/Minimum Spanning Tree (Unweighted)/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme index 8ef8d8581..afd69e6a7 100644 --- a/Minimum Spanning Tree (Unweighted)/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme +++ b/Minimum Spanning Tree (Unweighted)/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme @@ -1,6 +1,6 @@ Date: Sat, 13 Oct 2018 10:59:37 +0300 Subject: [PATCH 33/86] update Huffman Coding to Swift 4.2 --- Huffman Coding/Huffman.playground/Contents.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Huffman Coding/Huffman.playground/Contents.swift b/Huffman Coding/Huffman.playground/Contents.swift index 6242ad272..2d59908e9 100644 --- a/Huffman Coding/Huffman.playground/Contents.swift +++ b/Huffman Coding/Huffman.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - import Foundation let s1 = "so much words wow many compression" From 61400ea88862429ea588cf07e396377ca485d9b0 Mon Sep 17 00:00:00 2001 From: Viktor Sokolov Date: Sat, 13 Oct 2018 11:31:57 +0300 Subject: [PATCH 34/86] Update Multiset to Swift 4.2 --- Multiset/Multiset.playground/Contents.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Multiset/Multiset.playground/Contents.swift b/Multiset/Multiset.playground/Contents.swift index b4f64ee1f..64b729df1 100644 --- a/Multiset/Multiset.playground/Contents.swift +++ b/Multiset/Multiset.playground/Contents.swift @@ -1,9 +1,5 @@ //: Playground - noun: a place where people can play -#if swift(>=4.0) - print("Hello, Swift 4!") -#endif - import Cocoa var set = Multiset() From bb9ae3b6629da9b837c4cf33f9dfd977b13a635d Mon Sep 17 00:00:00 2001 From: Viktor Sokolov Date: Sat, 13 Oct 2018 11:39:24 +0300 Subject: [PATCH 35/86] Update Monty Hall to Swift 4.2 --- Monty Hall Problem/MontyHall.playground/Contents.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Monty Hall Problem/MontyHall.playground/Contents.swift b/Monty Hall Problem/MontyHall.playground/Contents.swift index 4bfff2340..a809410c7 100644 --- a/Monty Hall Problem/MontyHall.playground/Contents.swift +++ b/Monty Hall Problem/MontyHall.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) - print("Hello, Swift 4!") -#endif - import Foundation func random(_ n: Int) -> Int { From 33a50920ebefc92ce844d6f024e8c4a49f2eb3ef Mon Sep 17 00:00:00 2001 From: Viktor Sokolov Date: Sat, 13 Oct 2018 11:49:26 +0300 Subject: [PATCH 36/86] Update Ring Buffer to Swift 4.2 --- Ring Buffer/RingBuffer.playground/Contents.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Ring Buffer/RingBuffer.playground/Contents.swift b/Ring Buffer/RingBuffer.playground/Contents.swift index f9ddb9c99..adcf146b4 100644 --- a/Ring Buffer/RingBuffer.playground/Contents.swift +++ b/Ring Buffer/RingBuffer.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - public struct RingBuffer { fileprivate var array: [T?] fileprivate var readIndex = 0 From 58af4187be04c17586a3bb37f30fd269bffd2692 Mon Sep 17 00:00:00 2001 From: Nick Thompson Date: Sat, 13 Oct 2018 10:32:59 -0400 Subject: [PATCH 37/86] Updated LRU Cache to Swift 4.2 --- LRU Cache/LRUCache.playground/Contents.swift | 5 ----- .../playground.xcworkspace/contents.xcworkspacedata | 7 +++++++ .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 LRU Cache/LRUCache.playground/playground.xcworkspace/contents.xcworkspacedata create mode 100644 LRU Cache/LRUCache.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/LRU Cache/LRUCache.playground/Contents.swift b/LRU Cache/LRUCache.playground/Contents.swift index 2ebc03242..35dcc5d59 100644 --- a/LRU Cache/LRUCache.playground/Contents.swift +++ b/LRU Cache/LRUCache.playground/Contents.swift @@ -1,8 +1,3 @@ -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - let cache = LRUCache(2) cache.set("a", val: 1) cache.set("b", val: 2) diff --git a/LRU Cache/LRUCache.playground/playground.xcworkspace/contents.xcworkspacedata b/LRU Cache/LRUCache.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..919434a62 --- /dev/null +++ b/LRU Cache/LRUCache.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/LRU Cache/LRUCache.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/LRU Cache/LRUCache.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/LRU Cache/LRUCache.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From f7b3996dd301816a66618fc497edb546706e68d0 Mon Sep 17 00:00:00 2001 From: karolms Date: Sun, 14 Oct 2018 02:09:18 -0300 Subject: [PATCH 38/86] Updated Knuth-Morris-Pratt to Swift 4.2 --- .../KnuthMorrisPratt.playground/Contents.swift | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Knuth-Morris-Pratt/KnuthMorrisPratt.playground/Contents.swift b/Knuth-Morris-Pratt/KnuthMorrisPratt.playground/Contents.swift index 6609c9abe..9b4a50fa0 100644 --- a/Knuth-Morris-Pratt/KnuthMorrisPratt.playground/Contents.swift +++ b/Knuth-Morris-Pratt/KnuthMorrisPratt.playground/Contents.swift @@ -1,13 +1,8 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift4!") -#endif - func ZetaAlgorithm(ptnr: String) -> [Int]? { - let pattern = Array(ptnr.characters) + let pattern = Array(ptnr) let patternLength: Int = pattern.count guard patternLength > 0 else { @@ -65,7 +60,7 @@ extension String { func indexesOf(ptnr: String) -> [Int]? { - let text = Array(self.characters) + let text = Array(self) let pattern = Array(ptnr.characters) let textLength: Int = text.count From 32fe7e84c0378daacf3e4048cf2f4d55bdb22c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Afonso=20Gra=C3=A7a?= Date: Mon, 15 Oct 2018 13:25:42 +1100 Subject: [PATCH 39/86] [Swift 4.2] Update Miller-Rabin Primality Test References #748 There were no necessary code changes for Swift 4.2. Removed the snippet requested --- .../MRPrimality.playground/Contents.swift | 5 ----- .../playground.xcworkspace/contents.xcworkspacedata | 4 ++++ .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 Miller-Rabin Primality Test/MRPrimality.playground/playground.xcworkspace/contents.xcworkspacedata create mode 100644 Miller-Rabin Primality Test/MRPrimality.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Miller-Rabin Primality Test/MRPrimality.playground/Contents.swift b/Miller-Rabin Primality Test/MRPrimality.playground/Contents.swift index d8fd7fad8..98032bd59 100644 --- a/Miller-Rabin Primality Test/MRPrimality.playground/Contents.swift +++ b/Miller-Rabin Primality Test/MRPrimality.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - // Real primes mrPrimalityTest(5) mrPrimalityTest(439) diff --git a/Miller-Rabin Primality Test/MRPrimality.playground/playground.xcworkspace/contents.xcworkspacedata b/Miller-Rabin Primality Test/MRPrimality.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..94b2795e2 --- /dev/null +++ b/Miller-Rabin Primality Test/MRPrimality.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,4 @@ + + + diff --git a/Miller-Rabin Primality Test/MRPrimality.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Miller-Rabin Primality Test/MRPrimality.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Miller-Rabin Primality Test/MRPrimality.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From f95093e7338bc66d73ff81b52f959ec0f4fdd2b5 Mon Sep 17 00:00:00 2001 From: Michael Pchelnikov Date: Thu, 18 Oct 2018 00:28:16 +0300 Subject: [PATCH 40/86] Update Sorted Set to Swift 4.2 --- .../Pages/Example 1.xcplaygroundpage/Contents.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Sorted Set/SortedSet.playground/Pages/Example 1.xcplaygroundpage/Contents.swift b/Sorted Set/SortedSet.playground/Pages/Example 1.xcplaygroundpage/Contents.swift index 45af5f99d..c81f4d915 100644 --- a/Sorted Set/SortedSet.playground/Pages/Example 1.xcplaygroundpage/Contents.swift +++ b/Sorted Set/SortedSet.playground/Pages/Example 1.xcplaygroundpage/Contents.swift @@ -1,8 +1,3 @@ -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - //: # Example 1 with type Int var mySet = SortedSet() From 0c93543179946a42b44a11fb79061a6126a8d8b5 Mon Sep 17 00:00:00 2001 From: Erik Strottmann Date: Wed, 17 Oct 2018 22:01:48 -0700 Subject: [PATCH 41/86] Update Trie to Swift 4.2 Removes `#if swift(>=4.0)` checks and calls to deprecated `String.characters` property, and enables Xcode 10 recommended warnings. --- Trie/ReadMe.md | 4 +-- Trie/Trie/Trie.xcodeproj/project.pbxproj | 33 +++++++++++++++---- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++ Trie/Trie/Trie/Trie.swift | 11 ++----- Trie/Trie/Trie/ViewController.swift | 5 --- Trie/Trie/TrieTests/TrieTests.swift | 5 --- 6 files changed, 39 insertions(+), 27 deletions(-) create mode 100644 Trie/Trie/Trie.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Trie/ReadMe.md b/Trie/ReadMe.md index 34b9beb9c..8e473a619 100644 --- a/Trie/ReadMe.md +++ b/Trie/ReadMe.md @@ -33,7 +33,7 @@ func contains(word: String) -> Bool { var currentNode = root // 2 - var characters = Array(word.lowercased().characters) + var characters = Array(word.lowercased()) var currentIndex = 0 // 3 @@ -74,7 +74,7 @@ func insert(word: String) { var currentNode = root // 2 - for character in word.lowercased().characters { + for character in word.lowercased() { // 3 if let childNode = currentNode.children[character] { currentNode = childNode diff --git a/Trie/Trie/Trie.xcodeproj/project.pbxproj b/Trie/Trie/Trie.xcodeproj/project.pbxproj index 90c5734cc..1e3602eea 100644 --- a/Trie/Trie/Trie.xcodeproj/project.pbxproj +++ b/Trie/Trie/Trie.xcodeproj/project.pbxproj @@ -195,20 +195,23 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0810; - LastUpgradeCheck = 0820; + LastUpgradeCheck = 1000; ORGANIZATIONNAME = "Rick Zaccone"; TargetAttributes = { EB798DF91DFEF79900F0628D = { CreatedOnToolsVersion = 8.1; + LastSwiftMigration = 1000; ProvisioningStyle = Automatic; }; EB798E0A1DFEF79900F0628D = { CreatedOnToolsVersion = 8.1; + LastSwiftMigration = 1000; ProvisioningStyle = Automatic; TestTargetID = EB798DF91DFEF79900F0628D; }; EB798E151DFEF79900F0628D = { CreatedOnToolsVersion = 8.1; + LastSwiftMigration = 1000; ProvisioningStyle = Automatic; TestTargetID = EB798DF91DFEF79900F0628D; }; @@ -326,15 +329,23 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_UNREACHABLE_CODE = YES; @@ -376,15 +387,23 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_UNREACHABLE_CODE = YES; @@ -418,7 +437,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = edu.bucknell.zaccone.Trie; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -431,7 +450,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = edu.bucknell.zaccone.Trie; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -445,7 +464,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = edu.bucknell.zaccone.TrieTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Trie.app/Contents/MacOS/Trie"; }; name = Debug; @@ -460,7 +479,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = edu.bucknell.zaccone.TrieTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Trie.app/Contents/MacOS/Trie"; }; name = Release; @@ -474,7 +493,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = edu.bucknell.zaccone.TrieUITests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; TEST_TARGET_NAME = Trie; }; name = Debug; @@ -488,7 +507,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = edu.bucknell.zaccone.TrieUITests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; TEST_TARGET_NAME = Trie; }; name = Release; diff --git a/Trie/Trie/Trie.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Trie/Trie/Trie.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Trie/Trie/Trie.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Trie/Trie/Trie/Trie.swift b/Trie/Trie/Trie/Trie.swift index 1a7017c4c..fbc933138 100644 --- a/Trie/Trie/Trie/Trie.swift +++ b/Trie/Trie/Trie/Trie.swift @@ -6,11 +6,6 @@ // Copyright © 2016 Rick Zaccone. All rights reserved. // -// last checked with Xcode 9.0b4 -#if swift(>=4.0) - print("Hello, Swift 4!") -#endif - import Foundation /// A node in the trie @@ -105,7 +100,7 @@ extension Trie { return } var currentNode = root - for character in word.lowercased().characters { + for character in word.lowercased() { if let childNode = currentNode.children[character] { currentNode = childNode } else { @@ -130,7 +125,7 @@ extension Trie { return false } var currentNode = root - for character in word.lowercased().characters { + for character in word.lowercased() { guard let childNode = currentNode.children[character] else { return false } @@ -148,7 +143,7 @@ extension Trie { /// search failed. private func findLastNodeOf(word: String) -> Node? { var currentNode = root - for character in word.lowercased().characters { + for character in word.lowercased() { guard let childNode = currentNode.children[character] else { return nil } diff --git a/Trie/Trie/Trie/ViewController.swift b/Trie/Trie/Trie/ViewController.swift index 9c5e66163..928b01f4c 100644 --- a/Trie/Trie/Trie/ViewController.swift +++ b/Trie/Trie/Trie/ViewController.swift @@ -6,11 +6,6 @@ // Copyright © 2016 Rick Zaccone. All rights reserved. // -// last checked with Xcode 9.0b4 -#if swift(>=4.0) - print("Hello, Swift 4!") -#endif - import Cocoa class ViewController: NSViewController { diff --git a/Trie/Trie/TrieTests/TrieTests.swift b/Trie/Trie/TrieTests/TrieTests.swift index 45be03aad..b69c5666e 100644 --- a/Trie/Trie/TrieTests/TrieTests.swift +++ b/Trie/Trie/TrieTests/TrieTests.swift @@ -6,11 +6,6 @@ // Copyright © 2016 Rick Zaccone. All rights reserved. // -// last checked with Xcode 9.0b4 -#if swift(>=4.0) - print("Hello, Swift 4!") -#endif - import XCTest @testable import Trie From 66d0b867e22378465d83aecce1c30609906538d5 Mon Sep 17 00:00:00 2001 From: Randy the Dev <37282011+RandyTheDev@users.noreply.github.com> Date: Mon, 22 Oct 2018 03:05:09 +1100 Subject: [PATCH 42/86] Updated Radix Sort to Swift 4.2 --- Radix Sort/RadixSort.playground/Contents.swift | 15 ++------------- .../RadixSort.playground/Sources/radixSort.swift | 1 - 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/Radix Sort/RadixSort.playground/Contents.swift b/Radix Sort/RadixSort.playground/Contents.swift index 941723c37..0b549fc9e 100644 --- a/Radix Sort/RadixSort.playground/Contents.swift +++ b/Radix Sort/RadixSort.playground/Contents.swift @@ -1,21 +1,10 @@ //: Playground - noun: a place where people can play -import Cocoa - -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - // Test Radix Sort with small array of ten values var array: [Int] = [19, 4242, 2, 9, 912, 101, 55, 67, 89, 32] radixSort(&array) // Test Radix Sort with large array of 1000 random values -var bigArray = [Int](repeating: 0, count: 1000) -var i = 0 -while i < 1000 { - bigArray[i] = Int(arc4random_uniform(1000) + 1) - i += 1 -} +var bigArray = (0..<1000).map { _ in Int.random(in: 1...1000) } +bigArray radixSort(&bigArray) diff --git a/Radix Sort/RadixSort.playground/Sources/radixSort.swift b/Radix Sort/RadixSort.playground/Sources/radixSort.swift index 424d33fb9..af382f481 100644 --- a/Radix Sort/RadixSort.playground/Sources/radixSort.swift +++ b/Radix Sort/RadixSort.playground/Sources/radixSort.swift @@ -3,7 +3,6 @@ Sorting Algorithm that sorts an input array of integers digit by digit. */ -import Foundation // NOTE: This implementation does not handle negative numbers public func radixSort(_ array: inout [Int] ) { From 36ae366ea4faeb4bf96380df3d58ca4da34525c6 Mon Sep 17 00:00:00 2001 From: Randy the Dev <37282011+RandyTheDev@users.noreply.github.com> Date: Mon, 22 Oct 2018 04:01:21 +1100 Subject: [PATCH 43/86] Updated Radix Sort Tests to Swift 4.2 --- Radix Sort/Tests/RadixSortTests.swift | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Radix Sort/Tests/RadixSortTests.swift b/Radix Sort/Tests/RadixSortTests.swift index 9b881318a..688bcdcb8 100644 --- a/Radix Sort/Tests/RadixSortTests.swift +++ b/Radix Sort/Tests/RadixSortTests.swift @@ -9,13 +9,6 @@ import XCTest class RadixSortTests: XCTestCase { - func testSwift4() { - // last checked with Xcode 9.0b4 - #if swift(>=4.0) - print("Hello, Swift 4!") - #endif - } - func testCombSort() { let expectedSequence: [Int] = [2, 9, 19, 32, 55, 67, 89, 101, 912, 4242] var sequence = [19, 4242, 2, 9, 912, 101, 55, 67, 89, 32] From eab858255456bc4c3be0229cf852d91720ac3361 Mon Sep 17 00:00:00 2001 From: Rahul Sharma Date: Tue, 23 Oct 2018 18:08:08 +0530 Subject: [PATCH 44/86] [Swift 4.2] Updated Linear Search The code worked fine in Xcode 10. I removed code snippet at the top of playground file. --- Linear Search/LinearSearch.playground/Contents.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Linear Search/LinearSearch.playground/Contents.swift b/Linear Search/LinearSearch.playground/Contents.swift index 8ac0e9a71..8c616ded4 100644 --- a/Linear Search/LinearSearch.playground/Contents.swift +++ b/Linear Search/LinearSearch.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - func linearSearch(_ array: [T], _ object: T) -> Int? { for (index, obj) in array.enumerated() where obj == object { return index From 0f08fa9ddb315a55cca92d1fbabecb48a406cee8 Mon Sep 17 00:00:00 2001 From: Rahul Date: Tue, 23 Oct 2018 19:02:39 +0530 Subject: [PATCH 45/86] [Swift 4.2] Updated Selection Sort --- Selection Sort/SelectionSort.playground/Contents.swift | 5 ----- .../SelectionSort.playground/Sources/SelectionSort.swift | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Selection Sort/SelectionSort.playground/Contents.swift b/Selection Sort/SelectionSort.playground/Contents.swift index b16dadb8d..a552c9edb 100644 --- a/Selection Sort/SelectionSort.playground/Contents.swift +++ b/Selection Sort/SelectionSort.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - let list = [ 10, -1, 3, 9, 2, 27, 8, 5, 1, 3, 0, 26 ] selectionSort(list) selectionSort(list, <) diff --git a/Selection Sort/SelectionSort.playground/Sources/SelectionSort.swift b/Selection Sort/SelectionSort.playground/Sources/SelectionSort.swift index e7c66481d..e157319b4 100644 --- a/Selection Sort/SelectionSort.playground/Sources/SelectionSort.swift +++ b/Selection Sort/SelectionSort.playground/Sources/SelectionSort.swift @@ -3,7 +3,7 @@ /// - Parameter array: array of elements that conform to the Comparable protocol /// - Returns: an array in ascending order public func selectionSort(_ array: [T]) -> [T] { - return insertionSort(array, <) + return selectionSort(array, <) } /// Performs the Selection sort algorithm on a array using the provided comparisson method From e0c8738b1f1a16184d79158df9b65c6d42fc1568 Mon Sep 17 00:00:00 2001 From: Rahul Date: Tue, 23 Oct 2018 19:21:46 +0530 Subject: [PATCH 46/86] [Swift 4.2] Updated Linked List --- Linked List/LinkedList.playground/Contents.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Linked List/LinkedList.playground/Contents.swift b/Linked List/LinkedList.playground/Contents.swift index cfa3a8b45..76b911310 100644 --- a/Linked List/LinkedList.playground/Contents.swift +++ b/Linked List/LinkedList.playground/Contents.swift @@ -3,10 +3,6 @@ // For best results, don't forget to select "Show Rendered Markup" from XCode's "Editor" menu //: Linked List Class Declaration: -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif public final class LinkedList { @@ -459,7 +455,7 @@ var sum = 0 for element in collection { sum += element } -// sum is 15 +sum //15 // Another way of achieving the same result though 'reduce', another method defined in an extension of Sequence. Collections are Sequences. let result = collection.reduce(0) {$0 + $1} // 15 From 71b20f41f8e1926a3c4f10a8fc3eca05d98ab193 Mon Sep 17 00:00:00 2001 From: laurentaylormarshall Date: Tue, 23 Oct 2018 22:25:10 -0500 Subject: [PATCH 47/86] Removes Swift 4.0 checks and updates the Swift version to 4.2. --- Comb Sort/Comb Sort.playground/Contents.swift | 6 +---- Comb Sort/Tests/CombSortTests.swift | 1 + .../Tests/Tests.xcodeproj/project.pbxproj | 22 ++++++++++++++++--- .../xcshareddata/xcschemes/Tests.xcscheme | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Comb Sort/Comb Sort.playground/Contents.swift b/Comb Sort/Comb Sort.playground/Contents.swift index 39e24248a..1f7723838 100644 --- a/Comb Sort/Comb Sort.playground/Contents.swift +++ b/Comb Sort/Comb Sort.playground/Contents.swift @@ -2,11 +2,7 @@ // Created by Stephen Rutstein // 7-16-2016 -import Cocoa -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif +import Foundation // Test Comb Sort with small array of ten values let array = [2, 32, 9, -1, 89, 101, 55, -10, -12, 67] diff --git a/Comb Sort/Tests/CombSortTests.swift b/Comb Sort/Tests/CombSortTests.swift index e972c0a57..783fbd150 100644 --- a/Comb Sort/Tests/CombSortTests.swift +++ b/Comb Sort/Tests/CombSortTests.swift @@ -17,6 +17,7 @@ class CombSortTests: XCTestCase { print("Hello, Swift 4!") #endif } + override func setUp() { super.setUp() sequence = [2, 32, 9, -1, 89, 101, 55, -10, -12, 67] diff --git a/Comb Sort/Tests/Tests.xcodeproj/project.pbxproj b/Comb Sort/Tests/Tests.xcodeproj/project.pbxproj index 7530acbdc..14d059271 100644 --- a/Comb Sort/Tests/Tests.xcodeproj/project.pbxproj +++ b/Comb Sort/Tests/Tests.xcodeproj/project.pbxproj @@ -82,7 +82,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0820; - LastUpgradeCheck = 0820; + LastUpgradeCheck = 1000; ORGANIZATIONNAME = "Swift Algorithm Club"; TargetAttributes = { 056E92741E2483D300B30F52 = { @@ -142,15 +142,23 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -192,15 +200,23 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -235,7 +251,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "Swift-Algorithm-Club.Tests"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -248,7 +264,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "Swift-Algorithm-Club.Tests"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/Comb Sort/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme b/Comb Sort/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme index 55e697ad3..48faa2df7 100644 --- a/Comb Sort/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme +++ b/Comb Sort/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme @@ -1,6 +1,6 @@ Date: Tue, 23 Oct 2018 23:41:43 -0500 Subject: [PATCH 48/86] Removes Swift 4.0 check. Removes unused import. Refactors an if statement into a guard to be more Swift-y. Removes unnecessarily explicitly defining the function as public. --- Slow Sort/SlowSort.playground/Contents.swift | 7 +------ Slow Sort/SlowSort.swift | 8 ++------ 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/Slow Sort/SlowSort.playground/Contents.swift b/Slow Sort/SlowSort.playground/Contents.swift index 95bf80739..54c1e61ea 100644 --- a/Slow Sort/SlowSort.playground/Contents.swift +++ b/Slow Sort/SlowSort.playground/Contents.swift @@ -1,9 +1,4 @@ -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - var numberList = [1, 12, 9, 17, 13, 12] -slowsort(0, numberList.count-1, &numberList) +slowSort(0, numberList.count-1, &numberList) print(numberList) diff --git a/Slow Sort/SlowSort.swift b/Slow Sort/SlowSort.swift index 9f264a057..217733daa 100644 --- a/Slow Sort/SlowSort.swift +++ b/Slow Sort/SlowSort.swift @@ -6,12 +6,8 @@ // // -import Foundation - -public func slowsort(_ i: Int, _ j: Int, _ numberList: inout [Int]) { - if i>=j { - return - } +func slowSort(_ i: Int, _ j: Int, _ numberList: inout [Int]) { + guard if i < j else { return } let m = (i+j)/2 slowsort(i, m, &numberList) slowsort(m+1, j, &numberList) From b5d5c89353857a26589d2e03bd72f442b45e1aa9 Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 26 Oct 2018 12:17:59 +0200 Subject: [PATCH 49/86] Updated Binary Tree to Swift 4.2 --- Binary Tree/BinaryTree.playground/Contents.swift | 5 ----- Binary Tree/BinaryTree.playground/contents.xcplayground | 2 +- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 Binary Tree/BinaryTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Binary Tree/BinaryTree.playground/Contents.swift b/Binary Tree/BinaryTree.playground/Contents.swift index 9da194fed..b0bff577a 100644 --- a/Binary Tree/BinaryTree.playground/Contents.swift +++ b/Binary Tree/BinaryTree.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - public indirect enum BinaryTree { case node(BinaryTree, T, BinaryTree) case empty diff --git a/Binary Tree/BinaryTree.playground/contents.xcplayground b/Binary Tree/BinaryTree.playground/contents.xcplayground index 06828af92..69d154d1e 100644 --- a/Binary Tree/BinaryTree.playground/contents.xcplayground +++ b/Binary Tree/BinaryTree.playground/contents.xcplayground @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/Binary Tree/BinaryTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Binary Tree/BinaryTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Binary Tree/BinaryTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From 016ae7c90bc525246f925480b6c6aa92eab47e4f Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 26 Oct 2018 12:21:05 +0200 Subject: [PATCH 50/86] Update BitSet to Swift 4.2 --- Bit Set/BitSet.playground/Contents.swift | 5 ----- Bit Set/BitSet.playground/contents.xcplayground | 2 +- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 Bit Set/BitSet.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Bit Set/BitSet.playground/Contents.swift b/Bit Set/BitSet.playground/Contents.swift index 95253ea27..d11b36e8c 100644 --- a/Bit Set/BitSet.playground/Contents.swift +++ b/Bit Set/BitSet.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - // Create a bit set that stores 140 bits var bits = BitSet(size: 140) diff --git a/Bit Set/BitSet.playground/contents.xcplayground b/Bit Set/BitSet.playground/contents.xcplayground index 06828af92..69d154d1e 100644 --- a/Bit Set/BitSet.playground/contents.xcplayground +++ b/Bit Set/BitSet.playground/contents.xcplayground @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/Bit Set/BitSet.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Bit Set/BitSet.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Bit Set/BitSet.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From 6d8e795377902dc7dbdc6ad0a2231f62ba3a0d49 Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 26 Oct 2018 12:31:47 +0200 Subject: [PATCH 51/86] Update Bounded Priority Queue to Swift 4.2 --- .../BoundedPriorityQueue.playground/Contents.swift | 5 ----- .../BoundedPriorityQueue.playground/contents.xcplayground | 2 +- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ .../Tests/Tests.xcodeproj/project.pbxproj | 6 +++--- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 5 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 Bounded Priority Queue/BoundedPriorityQueue.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Bounded Priority Queue/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Bounded Priority Queue/BoundedPriorityQueue.playground/Contents.swift b/Bounded Priority Queue/BoundedPriorityQueue.playground/Contents.swift index f8e219c13..d6204abec 100644 --- a/Bounded Priority Queue/BoundedPriorityQueue.playground/Contents.swift +++ b/Bounded Priority Queue/BoundedPriorityQueue.playground/Contents.swift @@ -1,8 +1,3 @@ -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - struct Message: Comparable, CustomStringConvertible { let name: String let priority: Int diff --git a/Bounded Priority Queue/BoundedPriorityQueue.playground/contents.xcplayground b/Bounded Priority Queue/BoundedPriorityQueue.playground/contents.xcplayground index 06828af92..69d154d1e 100644 --- a/Bounded Priority Queue/BoundedPriorityQueue.playground/contents.xcplayground +++ b/Bounded Priority Queue/BoundedPriorityQueue.playground/contents.xcplayground @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/Bounded Priority Queue/BoundedPriorityQueue.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Bounded Priority Queue/BoundedPriorityQueue.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Bounded Priority Queue/BoundedPriorityQueue.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Bounded Priority Queue/Tests/Tests.xcodeproj/project.pbxproj b/Bounded Priority Queue/Tests/Tests.xcodeproj/project.pbxproj index 842c51695..11f907b47 100644 --- a/Bounded Priority Queue/Tests/Tests.xcodeproj/project.pbxproj +++ b/Bounded Priority Queue/Tests/Tests.xcodeproj/project.pbxproj @@ -86,7 +86,7 @@ TargetAttributes = { B80004B21C83E342001FE2D7 = { CreatedOnToolsVersion = 7.2.1; - LastSwiftMigration = 0820; + LastSwiftMigration = 1000; }; }; }; @@ -226,7 +226,7 @@ SDKROOT = macosx; SWIFT_OBJC_BRIDGING_HEADER = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -269,7 +269,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SWIFT_OBJC_BRIDGING_HEADER = ""; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/Bounded Priority Queue/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Bounded Priority Queue/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Bounded Priority Queue/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From 57f25c429638b6a607d3e67f9e70f3633e2a1045 Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 26 Oct 2018 13:16:15 +0200 Subject: [PATCH 52/86] Update Boyer Moore to Swift 4.2 --- .../BoyerMooreHorspool.playground/Contents.swift | 11 +++-------- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ Boyer-Moore-Horspool/BoyerMooreHorspool.swift | 6 +++--- Boyer-Moore-Horspool/Tests/BoyerMooreTests.swift | 4 ++-- .../Tests/Tests.xcodeproj/project.pbxproj | 14 ++++++++------ .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ .../xcshareddata/xcschemes/Tests.xcscheme | 4 +--- .../contents.xcworkspacedata | 6 +++--- 8 files changed, 36 insertions(+), 25 deletions(-) create mode 100644 Boyer-Moore-Horspool/BoyerMooreHorspool.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Boyer-Moore-Horspool/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift index e88a1b93d..1666549c1 100644 --- a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift +++ b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) - print("Hello, Swift 4!") -#endif - /* Boyer-Moore string search @@ -16,13 +11,13 @@ extension String { func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Index? { // Cache the length of the search pattern because we're going to // use it a few times and it's expensive to calculate. - let patternLength = pattern.characters.count - guard patternLength > 0, patternLength <= characters.count else { return nil } + let patternLength = pattern.count + guard patternLength > 0, patternLength <= count else { return nil } // Make the skip table. This table determines how far we skip ahead // when a character from the pattern is found. var skipTable = [Character: Int]() - for (i, c) in pattern.characters.enumerated() { + for (i, c) in pattern.enumerated() { skipTable[c] = patternLength - i - 1 } diff --git a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Boyer-Moore-Horspool/BoyerMooreHorspool.swift b/Boyer-Moore-Horspool/BoyerMooreHorspool.swift index af8aea9d9..dbd738740 100644 --- a/Boyer-Moore-Horspool/BoyerMooreHorspool.swift +++ b/Boyer-Moore-Horspool/BoyerMooreHorspool.swift @@ -9,13 +9,13 @@ extension String { func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Index? { // Cache the length of the search pattern because we're going to // use it a few times and it's expensive to calculate. - let patternLength = pattern.characters.count - guard patternLength > 0, patternLength <= characters.count else { return nil } + let patternLength = pattern.count + guard patternLength > 0, patternLength <= count else { return nil } // Make the skip table. This table determines how far we skip ahead // when a character from the pattern is found. var skipTable = [Character: Int]() - for (i, c) in pattern.characters.enumerated() { + for (i, c) in pattern.enumerated() { skipTable[c] = patternLength - i - 1 } diff --git a/Boyer-Moore-Horspool/Tests/BoyerMooreTests.swift b/Boyer-Moore-Horspool/Tests/BoyerMooreTests.swift index 9efe60874..436173127 100755 --- a/Boyer-Moore-Horspool/Tests/BoyerMooreTests.swift +++ b/Boyer-Moore-Horspool/Tests/BoyerMooreTests.swift @@ -26,8 +26,8 @@ class BoyerMooreTest: XCTestCase { XCTAssertNotNil(index) let startIndex = index! - let endIndex = string.index(index!, offsetBy: pattern.characters.count) - let match = string.substring(with: startIndex.. + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Boyer-Moore-Horspool/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme b/Boyer-Moore-Horspool/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme index 538a6f4fa..afd69e6a7 100644 --- a/Boyer-Moore-Horspool/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme +++ b/Boyer-Moore-Horspool/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme @@ -1,6 +1,6 @@ + location = "group:Boyer-Moore-Horspool/BoyerMooreHorspool.playground"> + location = "group:Boyer-Moore-Horspool/BoyerMooreHorspool.swift"> From 7384ec29e4e95cbae0b6a93dc6ae2ffe66eecffb Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 26 Oct 2018 13:20:32 +0200 Subject: [PATCH 53/86] Update Boyer Moore to Swift 4.2 --- .../contents.xcworkspacedata | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/swift-algorithm-club.xcworkspace/contents.xcworkspacedata b/swift-algorithm-club.xcworkspace/contents.xcworkspacedata index 04d4ac573..d85d538b3 100644 --- a/swift-algorithm-club.xcworkspace/contents.xcworkspacedata +++ b/swift-algorithm-club.xcworkspace/contents.xcworkspacedata @@ -609,19 +609,19 @@ + location = "group:BoyerMooreHorspool.playground"> + location = "group:BoyerMooreHorspool.swift"> @@ -633,7 +633,7 @@ location = "group:Info.plist"> + location = "group:/Users/mroedder/workspace/swift-algorithm-club/Boyer-Moore-Horspool/Tests/Tests.xcodeproj"> From 402f23669b3f5c06dbd64adfe885d873e3a23f65 Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 26 Oct 2018 13:24:39 +0200 Subject: [PATCH 54/86] Update Boyer Moore to Swift 4.2 --- swift-algorithm-club.xcworkspace/contents.xcworkspacedata | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swift-algorithm-club.xcworkspace/contents.xcworkspacedata b/swift-algorithm-club.xcworkspace/contents.xcworkspacedata index d85d538b3..a37dac494 100644 --- a/swift-algorithm-club.xcworkspace/contents.xcworkspacedata +++ b/swift-algorithm-club.xcworkspace/contents.xcworkspacedata @@ -633,7 +633,7 @@ location = "group:Info.plist"> + location = "group:Tests/Tests.xcodeproj"> From 6ead6d0dcb0e77f51cbda0582a1b6f56c1d0ebd0 Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 26 Oct 2018 13:27:09 +0200 Subject: [PATCH 55/86] Update README to use Swift 4.2 --- Boyer-Moore-Horspool/README.markdown | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Boyer-Moore-Horspool/README.markdown b/Boyer-Moore-Horspool/README.markdown index f5e21ea41..8879d8df6 100644 --- a/Boyer-Moore-Horspool/README.markdown +++ b/Boyer-Moore-Horspool/README.markdown @@ -38,13 +38,13 @@ extension String { func index(of pattern: String) -> Index? { // Cache the length of the search pattern because we're going to // use it a few times and it's expensive to calculate. - let patternLength = pattern.characters.count - guard patternLength > 0, patternLength <= characters.count else { return nil } + let patternLength = pattern.count + guard patternLength > 0, patternLength <= count else { return nil } // Make the skip table. This table determines how far we skip ahead // when a character from the pattern is found. var skipTable = [Character: Int]() - for (i, c) in pattern.characters.enumerated() { + for (i, c) in pattern.enumerated() { skipTable[c] = patternLength - i - 1 } @@ -162,13 +162,13 @@ extension String { func index(of pattern: String) -> Index? { // Cache the length of the search pattern because we're going to // use it a few times and it's expensive to calculate. - let patternLength = pattern.characters.count + let patternLength = pattern.count guard patternLength > 0, patternLength <= characters.count else { return nil } // Make the skip table. This table determines how far we skip ahead // when a character from the pattern is found. var skipTable = [Character: Int]() - for (i, c) in pattern.characters.enumerated() { + for (i, c) in pattern.enumerated() { skipTable[c] = patternLength - i - 1 } From 13d152600da95a0864d14edae72c0d93c161781c Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 26 Oct 2018 13:41:18 +0200 Subject: [PATCH 56/86] Update Breadth First Search to Swift 4.2 --- .../Contents.swift | 4 --- .../Sources/Graph.swift | 2 +- .../contents.xcplayground | 2 +- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++ .../Tests/Tests.xcodeproj/project.pbxproj | 30 +++++++++++++++---- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++ .../xcshareddata/xcschemes/Tests.xcscheme | 2 +- 7 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 Breadth-First Search/BreadthFirstSearch.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Breadth-First Search/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Breadth-First Search/BreadthFirstSearch.playground/Pages/Simple example.xcplaygroundpage/Contents.swift b/Breadth-First Search/BreadthFirstSearch.playground/Pages/Simple example.xcplaygroundpage/Contents.swift index 3986a0cee..cf22ebb25 100644 --- a/Breadth-First Search/BreadthFirstSearch.playground/Pages/Simple example.xcplaygroundpage/Contents.swift +++ b/Breadth-First Search/BreadthFirstSearch.playground/Pages/Simple example.xcplaygroundpage/Contents.swift @@ -1,7 +1,3 @@ -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif func breadthFirstSearch(_ graph: Graph, source: Node) -> [String] { var queue = Queue() diff --git a/Breadth-First Search/BreadthFirstSearch.playground/Sources/Graph.swift b/Breadth-First Search/BreadthFirstSearch.playground/Sources/Graph.swift index 87e21897c..0343120f8 100644 --- a/Breadth-First Search/BreadthFirstSearch.playground/Sources/Graph.swift +++ b/Breadth-First Search/BreadthFirstSearch.playground/Sources/Graph.swift @@ -5,7 +5,7 @@ public class Graph: CustomStringConvertible, Equatable { self.nodes = [] } - public func addNode(_ label: String) -> Node { + @discardableResult public func addNode(_ label: String) -> Node { let node = Node(label) nodes.append(node) return node diff --git a/Breadth-First Search/BreadthFirstSearch.playground/contents.xcplayground b/Breadth-First Search/BreadthFirstSearch.playground/contents.xcplayground index 513c2e7e9..f635e9804 100644 --- a/Breadth-First Search/BreadthFirstSearch.playground/contents.xcplayground +++ b/Breadth-First Search/BreadthFirstSearch.playground/contents.xcplayground @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/Breadth-First Search/BreadthFirstSearch.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Breadth-First Search/BreadthFirstSearch.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Breadth-First Search/BreadthFirstSearch.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Breadth-First Search/Tests/Tests.xcodeproj/project.pbxproj b/Breadth-First Search/Tests/Tests.xcodeproj/project.pbxproj index f86abf86e..a7f04e00a 100644 --- a/Breadth-First Search/Tests/Tests.xcodeproj/project.pbxproj +++ b/Breadth-First Search/Tests/Tests.xcodeproj/project.pbxproj @@ -59,7 +59,6 @@ 7B2BBC941C779E7B0067B71D /* Info.plist */, ); name = Tests; - path = TestsTests; sourceTree = ""; }; /* End PBXGroup section */ @@ -89,12 +88,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0820; + LastUpgradeCheck = 1000; ORGANIZATIONNAME = "Swift Algorithm Club"; TargetAttributes = { 7B2BBC7F1C779D720067B71D = { CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 0820; + LastSwiftMigration = 1000; }; }; }; @@ -149,13 +148,23 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; @@ -193,13 +202,23 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; @@ -218,6 +237,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; }; name = Release; }; @@ -231,7 +251,7 @@ PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -244,7 +264,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/Breadth-First Search/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Breadth-First Search/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Breadth-First Search/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Breadth-First Search/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme b/Breadth-First Search/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme index dfcf6de42..afd69e6a7 100644 --- a/Breadth-First Search/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme +++ b/Breadth-First Search/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme @@ -1,6 +1,6 @@ Date: Sat, 27 Oct 2018 10:26:54 -0700 Subject: [PATCH 57/86] Standardize Trie indentation to 2 spaces 2 spaces is recommended by the Ray Wenderlich Swift Style Guide. --- Trie/ReadMe.md | 40 +-- Trie/Trie/Trie.xcodeproj/project.pbxproj | 2 + Trie/Trie/Trie/AppDelegate.swift | 12 +- Trie/Trie/Trie/Trie.swift | 118 ++++---- Trie/Trie/Trie/ViewController.swift | 16 +- Trie/Trie/TrieTests/TrieTests.swift | 340 +++++++++++------------ Trie/Trie/TrieUITests/TrieUITests.swift | 34 +-- 7 files changed, 280 insertions(+), 282 deletions(-) diff --git a/Trie/ReadMe.md b/Trie/ReadMe.md index 8e473a619..8d0c45c8a 100644 --- a/Trie/ReadMe.md +++ b/Trie/ReadMe.md @@ -27,29 +27,29 @@ Tries are very useful for certain situations. Here are some of the advantages: ```swift func contains(word: String) -> Bool { - guard !word.isEmpty else { return false } + guard !word.isEmpty else { return false } - // 1 - var currentNode = root + // 1 + var currentNode = root - // 2 - var characters = Array(word.lowercased()) - var currentIndex = 0 + // 2 + var characters = Array(word.lowercased()) + var currentIndex = 0 - // 3 - while currentIndex < characters.count, - let child = currentNode.children[characters[currentIndex]] { - - currentNode = child - currentIndex += 1 - } - - // 4 - if currentIndex == characters.count && currentNode.isTerminating { - return true - } else { - return false - } + // 3 + while currentIndex < characters.count, + let child = currentNode.children[characters[currentIndex]] { + + currentNode = child + currentIndex += 1 + } + + // 4 + if currentIndex == characters.count && currentNode.isTerminating { + return true + } else { + return false + } } ``` diff --git a/Trie/Trie/Trie.xcodeproj/project.pbxproj b/Trie/Trie/Trie.xcodeproj/project.pbxproj index 1e3602eea..6b7cc9b61 100644 --- a/Trie/Trie/Trie.xcodeproj/project.pbxproj +++ b/Trie/Trie/Trie.xcodeproj/project.pbxproj @@ -87,7 +87,9 @@ EB798E191DFEF79900F0628D /* TrieUITests */, EB798DFB1DFEF79900F0628D /* Products */, ); + indentWidth = 2; sourceTree = ""; + tabWidth = 2; }; EB798DFB1DFEF79900F0628D /* Products */ = { isa = PBXGroup; diff --git a/Trie/Trie/Trie/AppDelegate.swift b/Trie/Trie/Trie/AppDelegate.swift index b2c46695b..48dc24673 100644 --- a/Trie/Trie/Trie/AppDelegate.swift +++ b/Trie/Trie/Trie/AppDelegate.swift @@ -11,12 +11,12 @@ import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { - func applicationDidFinishLaunching(_ aNotification: Notification) { - // Insert code here to initialize your application - } + func applicationDidFinishLaunching(_ aNotification: Notification) { + // Insert code here to initialize your application + } - func applicationWillTerminate(_ aNotification: Notification) { - // Insert code here to tear down your application - } + func applicationWillTerminate(_ aNotification: Notification) { + // Insert code here to tear down your application + } } diff --git a/Trie/Trie/Trie/Trie.swift b/Trie/Trie/Trie/Trie.swift index fbc933138..accc7b61c 100644 --- a/Trie/Trie/Trie/Trie.swift +++ b/Trie/Trie/Trie/Trie.swift @@ -43,54 +43,53 @@ class TrieNode { /// A trie data structure containing words. Each node is a single /// character of a word. class Trie: NSObject, NSCoding { - typealias Node = TrieNode - /// The number of words in the trie - public var count: Int { - return wordCount - } - /// Is the trie empty? - public var isEmpty: Bool { - return wordCount == 0 - } - /// All words currently in the trie - public var words: [String] { - return wordsInSubtrie(rootNode: root, partialWord: "") - } - fileprivate let root: Node - fileprivate var wordCount: Int - - /// Creates an empty trie. - override init() { - root = Node() - wordCount = 0 - super.init() - } + typealias Node = TrieNode + /// The number of words in the trie + public var count: Int { + return wordCount + } + /// Is the trie empty? + public var isEmpty: Bool { + return wordCount == 0 + } + /// All words currently in the trie + public var words: [String] { + return wordsInSubtrie(rootNode: root, partialWord: "") + } + fileprivate let root: Node + fileprivate var wordCount: Int + + /// Creates an empty trie. + override init() { + root = Node() + wordCount = 0 + super.init() + } - // MARK: NSCoding + // MARK: NSCoding - /// Initializes the trie with words from an archive - /// - /// - Parameter decoder: Decodes the archive - required convenience init?(coder decoder: NSCoder) { - self.init() - let words = decoder.decodeObject(forKey: "words") as? [String] - for word in words! { - self.insert(word: word) - } + /// Initializes the trie with words from an archive + /// + /// - Parameter decoder: Decodes the archive + required convenience init?(coder decoder: NSCoder) { + self.init() + let words = decoder.decodeObject(forKey: "words") as? [String] + for word in words! { + self.insert(word: word) } + } - /// Encodes the words in the trie by putting them in an array then encoding - /// the array. - /// - /// - Parameter coder: The object that will encode the array - func encode(with coder: NSCoder) { - coder.encode(self.words, forKey: "words") - } + /// Encodes the words in the trie by putting them in an array then encoding + /// the array. + /// + /// - Parameter coder: The object that will encode the array + func encode(with coder: NSCoder) { + coder.encode(self.words, forKey: "words") + } } // MARK: - Adds methods: insert, remove, contains extension Trie { - /// Inserts a word into the trie. If the word is already present, /// there is no change. /// @@ -142,14 +141,14 @@ extension Trie { /// - Returns: the node where the search ended, nil if the /// search failed. private func findLastNodeOf(word: String) -> Node? { - var currentNode = root - for character in word.lowercased() { - guard let childNode = currentNode.children[character] else { - return nil - } - currentNode = childNode + var currentNode = root + for character in word.lowercased() { + guard let childNode = currentNode.children[character] else { + return nil } - return currentNode + currentNode = childNode + } + return currentNode } /// Attempts to walk to the terminating node of a word. The @@ -160,10 +159,9 @@ extension Trie { /// search failed. private func findTerminalNodeOf(word: String) -> Node? { if let lastNode = findLastNodeOf(word: word) { - return lastNode.isTerminating ? lastNode : nil + return lastNode.isTerminating ? lastNode : nil } return nil - } /// Deletes a word from the trie by starting with the last letter @@ -237,17 +235,17 @@ extension Trie { /// - prefix: the letters for word prefix /// - Returns: the words in the subtrie that start with prefix func findWordsWithPrefix(prefix: String) -> [String] { - var words = [String]() - let prefixLowerCased = prefix.lowercased() - if let lastNode = findLastNodeOf(word: prefixLowerCased) { - if lastNode.isTerminating { - words.append(prefixLowerCased) - } - for childNode in lastNode.children.values { - let childWords = wordsInSubtrie(rootNode: childNode, partialWord: prefixLowerCased) - words += childWords - } + var words = [String]() + let prefixLowerCased = prefix.lowercased() + if let lastNode = findLastNodeOf(word: prefixLowerCased) { + if lastNode.isTerminating { + words.append(prefixLowerCased) + } + for childNode in lastNode.children.values { + let childWords = wordsInSubtrie(rootNode: childNode, partialWord: prefixLowerCased) + words += childWords } - return words + } + return words } } diff --git a/Trie/Trie/Trie/ViewController.swift b/Trie/Trie/Trie/ViewController.swift index 928b01f4c..8ce34f6c7 100644 --- a/Trie/Trie/Trie/ViewController.swift +++ b/Trie/Trie/Trie/ViewController.swift @@ -10,16 +10,16 @@ import Cocoa class ViewController: NSViewController { - override func viewDidLoad() { - super.viewDidLoad() + override func viewDidLoad() { + super.viewDidLoad() - // Do any additional setup after loading the view. - } + // Do any additional setup after loading the view. + } - override var representedObject: Any? { - didSet { - // Update the view, if already loaded. - } + override var representedObject: Any? { + didSet { + // Update the view, if already loaded. } + } } diff --git a/Trie/Trie/TrieTests/TrieTests.swift b/Trie/Trie/TrieTests/TrieTests.swift index b69c5666e..0c5bc69c6 100644 --- a/Trie/Trie/TrieTests/TrieTests.swift +++ b/Trie/Trie/TrieTests/TrieTests.swift @@ -10,186 +10,184 @@ import XCTest @testable import Trie class TrieTests: XCTestCase { - var wordArray: [String]? - var trie = Trie() - - /// Makes sure that the wordArray and trie are initialized before each test. - override func setUp() { - super.setUp() - createWordArray() - insertWordsIntoTrie() + var wordArray: [String]? + var trie = Trie() + + /// Makes sure that the wordArray and trie are initialized before each test. + override func setUp() { + super.setUp() + createWordArray() + insertWordsIntoTrie() + } + + /// Don't need to do anything here because the wordArray and trie should + /// stay around. + override func tearDown() { + super.tearDown() + } + + /// Reads words from the dictionary file and inserts them into an array. If + /// the word array already has words, do nothing. This allows running all + /// tests without repeatedly filling the array with the same values. + func createWordArray() { + guard wordArray == nil else { + return } - - /// Don't need to do anything here because the wordArray and trie should - /// stay around. - override func tearDown() { - super.tearDown() - } - - /// Reads words from the dictionary file and inserts them into an array. If - /// the word array already has words, do nothing. This allows running all - /// tests without repeatedly filling the array with the same values. - func createWordArray() { - guard wordArray == nil else { - return - } - let resourcePath = Bundle.main.resourcePath! as NSString - let fileName = "dictionary.txt" - let filePath = resourcePath.appendingPathComponent(fileName) - - var data: String? - do { - data = try String(contentsOfFile: filePath, encoding: String.Encoding.utf8) - } catch let error as NSError { - XCTAssertNil(error) - } - XCTAssertNotNil(data) - let dictionarySize = 162825 - wordArray = data!.components(separatedBy: "\n") - XCTAssertEqual(wordArray!.count, dictionarySize) - } - - /// Inserts words into a trie. If the trie is non-empty, don't do anything. - func insertWordsIntoTrie() { - guard let wordArray = wordArray, trie.count == 0 else { return } - for word in wordArray { - trie.insert(word: word) - } - } - - /// Tests that a newly created trie has zero words. - func testCreate() { - let trie = Trie() - XCTAssertEqual(trie.count, 0) - } - - /// Tests the insert method - func testInsert() { - let trie = Trie() - trie.insert(word: "cute") - trie.insert(word: "cutie") - trie.insert(word: "fred") - XCTAssertTrue(trie.contains(word: "cute")) - XCTAssertFalse(trie.contains(word: "cut")) - trie.insert(word: "cut") - XCTAssertTrue(trie.contains(word: "cut")) - XCTAssertEqual(trie.count, 4) - } - - /// Tests the remove method - func testRemove() { - let trie = Trie() - trie.insert(word: "cute") - trie.insert(word: "cut") - XCTAssertEqual(trie.count, 2) - trie.remove(word: "cute") - XCTAssertTrue(trie.contains(word: "cut")) - XCTAssertFalse(trie.contains(word: "cute")) - XCTAssertEqual(trie.count, 1) + let resourcePath = Bundle.main.resourcePath! as NSString + let fileName = "dictionary.txt" + let filePath = resourcePath.appendingPathComponent(fileName) + + var data: String? + do { + data = try String(contentsOfFile: filePath, encoding: String.Encoding.utf8) + } catch let error as NSError { + XCTAssertNil(error) } - - /// Tests the words property - func testWords() { - let trie = Trie() - var words = trie.words - XCTAssertEqual(words.count, 0) - trie.insert(word: "foobar") - words = trie.words - XCTAssertEqual(words[0], "foobar") - XCTAssertEqual(words.count, 1) + XCTAssertNotNil(data) + let dictionarySize = 162825 + wordArray = data!.components(separatedBy: "\n") + XCTAssertEqual(wordArray!.count, dictionarySize) + } + + /// Inserts words into a trie. If the trie is non-empty, don't do anything. + func insertWordsIntoTrie() { + guard let wordArray = wordArray, trie.count == 0 else { return } + for word in wordArray { + trie.insert(word: word) } - - /// Tests the performance of the insert method. - func testInsertPerformance() { - self.measure { - let trie = Trie() - for word in self.wordArray! { - trie.insert(word: word) - } - } - XCTAssertGreaterThan(trie.count, 0) - XCTAssertEqual(trie.count, wordArray?.count) + } + + /// Tests that a newly created trie has zero words. + func testCreate() { + let trie = Trie() + XCTAssertEqual(trie.count, 0) + } + + /// Tests the insert method + func testInsert() { + let trie = Trie() + trie.insert(word: "cute") + trie.insert(word: "cutie") + trie.insert(word: "fred") + XCTAssertTrue(trie.contains(word: "cute")) + XCTAssertFalse(trie.contains(word: "cut")) + trie.insert(word: "cut") + XCTAssertTrue(trie.contains(word: "cut")) + XCTAssertEqual(trie.count, 4) + } + + /// Tests the remove method + func testRemove() { + let trie = Trie() + trie.insert(word: "cute") + trie.insert(word: "cut") + XCTAssertEqual(trie.count, 2) + trie.remove(word: "cute") + XCTAssertTrue(trie.contains(word: "cut")) + XCTAssertFalse(trie.contains(word: "cute")) + XCTAssertEqual(trie.count, 1) + } + + /// Tests the words property + func testWords() { + let trie = Trie() + var words = trie.words + XCTAssertEqual(words.count, 0) + trie.insert(word: "foobar") + words = trie.words + XCTAssertEqual(words[0], "foobar") + XCTAssertEqual(words.count, 1) + } + + /// Tests the performance of the insert method. + func testInsertPerformance() { + self.measure { + let trie = Trie() + for word in self.wordArray! { + trie.insert(word: word) + } } - - /// Tests the performance of the insert method when the words are already - /// present. - func testInsertAgainPerformance() { - self.measure { - for word in self.wordArray! { - self.trie.insert(word: word) - } - } + XCTAssertGreaterThan(trie.count, 0) + XCTAssertEqual(trie.count, wordArray?.count) + } + + /// Tests the performance of the insert method when the words are already + /// present. + func testInsertAgainPerformance() { + self.measure { + for word in self.wordArray! { + self.trie.insert(word: word) + } } - - /// Tests the performance of the contains method. - func testContainsPerformance() { - self.measure { - for word in self.wordArray! { - XCTAssertTrue(self.trie.contains(word: word)) - } - } + } + + /// Tests the performance of the contains method. + func testContainsPerformance() { + self.measure { + for word in self.wordArray! { + XCTAssertTrue(self.trie.contains(word: word)) + } } + } - /// Tests the performance of the remove method. Since setup has already put - /// words into the trie, remove them before measuring performance. - func testRemovePerformance() { - for word in self.wordArray! { - self.trie.remove(word: word) - } - self.measure { - self.insertWordsIntoTrie() - for word in self.wordArray! { - self.trie.remove(word: word) - } - } - XCTAssertEqual(trie.count, 0) + /// Tests the performance of the remove method. Since setup has already put + /// words into the trie, remove them before measuring performance. + func testRemovePerformance() { + for word in self.wordArray! { + self.trie.remove(word: word) } - - /// Tests the performance of the words computed property. Also tests to see - /// if it worked properly. - func testWordsPerformance() { - var words: [String]? - self.measure { - words = self.trie.words - } - XCTAssertEqual(words?.count, trie.count) - for word in words! { - XCTAssertTrue(self.trie.contains(word: word)) - } + self.measure { + self.insertWordsIntoTrie() + for word in self.wordArray! { + self.trie.remove(word: word) + } } - - /// Tests the archiving and unarchiving of the trie. - func testArchiveAndUnarchive() { - let resourcePath = Bundle.main.resourcePath! as NSString - let fileName = "dictionary-archive" - let filePath = resourcePath.appendingPathComponent(fileName) - NSKeyedArchiver.archiveRootObject(trie, toFile: filePath) - let trieCopy = NSKeyedUnarchiver.unarchiveObject(withFile: filePath) as? Trie - XCTAssertEqual(trieCopy?.count, trie.count) - + XCTAssertEqual(trie.count, 0) + } + + /// Tests the performance of the words computed property. Also tests to see + /// if it worked properly. + func testWordsPerformance() { + var words: [String]? + self.measure { + words = self.trie.words } - - func testFindWordsWithPrefix() { - let trie = Trie() - trie.insert(word: "test") - trie.insert(word: "another") - trie.insert(word: "exam") - let wordsAll = trie.findWordsWithPrefix(prefix: "") - XCTAssertEqual(wordsAll.sorted(), ["another", "exam", "test"]) - let words = trie.findWordsWithPrefix(prefix: "ex") - XCTAssertEqual(words, ["exam"]) - trie.insert(word: "examination") - let words2 = trie.findWordsWithPrefix(prefix: "exam") - XCTAssertEqual(words2, ["exam", "examination"]) - let noWords = trie.findWordsWithPrefix(prefix: "tee") - XCTAssertEqual(noWords, []) - let unicodeWord = "😬😎" - trie.insert(word: unicodeWord) - let wordsUnicode = trie.findWordsWithPrefix(prefix: "😬") - XCTAssertEqual(wordsUnicode, [unicodeWord]) - trie.insert(word: "Team") - let wordsUpperCase = trie.findWordsWithPrefix(prefix: "Te") - XCTAssertEqual(wordsUpperCase.sorted(), ["team", "test"]) - + XCTAssertEqual(words?.count, trie.count) + for word in words! { + XCTAssertTrue(self.trie.contains(word: word)) } + } + + /// Tests the archiving and unarchiving of the trie. + func testArchiveAndUnarchive() { + let resourcePath = Bundle.main.resourcePath! as NSString + let fileName = "dictionary-archive" + let filePath = resourcePath.appendingPathComponent(fileName) + NSKeyedArchiver.archiveRootObject(trie, toFile: filePath) + let trieCopy = NSKeyedUnarchiver.unarchiveObject(withFile: filePath) as? Trie + XCTAssertEqual(trieCopy?.count, trie.count) + } + + func testFindWordsWithPrefix() { + let trie = Trie() + trie.insert(word: "test") + trie.insert(word: "another") + trie.insert(word: "exam") + let wordsAll = trie.findWordsWithPrefix(prefix: "") + XCTAssertEqual(wordsAll.sorted(), ["another", "exam", "test"]) + let words = trie.findWordsWithPrefix(prefix: "ex") + XCTAssertEqual(words, ["exam"]) + trie.insert(word: "examination") + let words2 = trie.findWordsWithPrefix(prefix: "exam") + XCTAssertEqual(words2, ["exam", "examination"]) + let noWords = trie.findWordsWithPrefix(prefix: "tee") + XCTAssertEqual(noWords, []) + let unicodeWord = "😬😎" + trie.insert(word: unicodeWord) + let wordsUnicode = trie.findWordsWithPrefix(prefix: "😬") + XCTAssertEqual(wordsUnicode, [unicodeWord]) + trie.insert(word: "Team") + let wordsUpperCase = trie.findWordsWithPrefix(prefix: "Te") + XCTAssertEqual(wordsUpperCase.sorted(), ["team", "test"]) + } } diff --git a/Trie/Trie/TrieUITests/TrieUITests.swift b/Trie/Trie/TrieUITests/TrieUITests.swift index acb3b1756..380bf3092 100644 --- a/Trie/Trie/TrieUITests/TrieUITests.swift +++ b/Trie/Trie/TrieUITests/TrieUITests.swift @@ -10,27 +10,27 @@ import XCTest class TrieUITests: XCTestCase { - override func setUp() { - super.setUp() + override func setUp() { + super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. + // Put setup code here. This method is called before the invocation of each test method in the class. - // In UI tests it is usually best to stop immediately when a failure occurs. - continueAfterFailure = false - // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. - XCUIApplication().launch() + // In UI tests it is usually best to stop immediately when a failure occurs. + continueAfterFailure = false + // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. + XCUIApplication().launch() - // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. - } + // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. + } - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - } + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } - func testExample() { - // Use recording to get started writing UI tests. - // Use XCTAssert and related functions to verify your tests produce the correct results. - } + func testExample() { + // Use recording to get started writing UI tests. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } } From 41eb9c1ee1591472c24b49108295261f698a3f1b Mon Sep 17 00:00:00 2001 From: Samwel Charles Date: Mon, 29 Oct 2018 00:22:43 +0300 Subject: [PATCH 58/86] update union-find to swift 4.2 --- Union-Find/UnionFind.playground/Contents.swift | 5 ----- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 Union-Find/UnionFind.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Union-Find/UnionFind.playground/Contents.swift b/Union-Find/UnionFind.playground/Contents.swift index 6ac3b4c4e..b1f7fb4e1 100644 --- a/Union-Find/UnionFind.playground/Contents.swift +++ b/Union-Find/UnionFind.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - var dsu = UnionFindQuickUnion() for i in 1...10 { diff --git a/Union-Find/UnionFind.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Union-Find/UnionFind.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Union-Find/UnionFind.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From cb76b97e3f295d171267044ca599d27db113a7ee Mon Sep 17 00:00:00 2001 From: Samwel Charles Date: Mon, 29 Oct 2018 01:01:09 +0300 Subject: [PATCH 59/86] add link to merge sort algorithm in buble sort algorith README.md file --- Bubble Sort/README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Bubble Sort/README.markdown b/Bubble Sort/README.markdown index e55129d93..c4b2c37c8 100644 --- a/Bubble Sort/README.markdown +++ b/Bubble Sort/README.markdown @@ -117,7 +117,7 @@ There is no Fifth pass #### Conclusion -Even with the proposed optimizations, this is still a terribly inefficient sorting algorithm. A good alternative is [Merge Sort](), that not only is better performing, has a similar degree of dificulty to implement. +Even with the proposed optimizations, this is still a terribly inefficient sorting algorithm. A good alternative is [Merge Sort](https://github.com/raywenderlich/swift-algorithm-club/tree/master/Merge%20Sort), that not only is better performing, has a similar degree of dificulty to implement. *Updated for the Swift Algorithm Club by Julio Brazil* From 299a67caeb984577561aaf1921271015558bfd6e Mon Sep 17 00:00:00 2001 From: Julio Brazil Date: Mon, 29 Oct 2018 11:45:21 -0300 Subject: [PATCH 60/86] addition of convenience method --- Bubble Sort/MyPlayground.playground/Contents.swift | 4 +++- .../MyPlayground.playground/Sources/BubbleSort.swift | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Bubble Sort/MyPlayground.playground/Contents.swift b/Bubble Sort/MyPlayground.playground/Contents.swift index 8d27d801e..6188a0763 100644 --- a/Bubble Sort/MyPlayground.playground/Contents.swift +++ b/Bubble Sort/MyPlayground.playground/Contents.swift @@ -3,4 +3,6 @@ import Foundation var array = [4,2,1,3] print("before:",array) -print("after:",BubbleSort(array)) +print("after:", bubbleSort(array)) +print("after:", bubbleSort(array, <)) +print("after:", bubbleSort(array, >)) diff --git a/Bubble Sort/MyPlayground.playground/Sources/BubbleSort.swift b/Bubble Sort/MyPlayground.playground/Sources/BubbleSort.swift index 9c091b661..09e01542b 100644 --- a/Bubble Sort/MyPlayground.playground/Sources/BubbleSort.swift +++ b/Bubble Sort/MyPlayground.playground/Sources/BubbleSort.swift @@ -23,14 +23,18 @@ import Foundation /// Performs the bubble sort algorithm in the array /// -/// - Parameter elements: the array to be sorted +/// - Parameter elements: a array of elements that implement the Comparable protocol /// - Returns: an array with the same elements but in order -public func BubbleSort (_ elements: [T]) -> [T] where T: Comparable { +public func bubbleSort (_ elements: [T]) -> [T] where T: Comparable { + return bubbleSort(elements, <) +} + +public func bubbleSort (_ elements: [T], _ comparison: (T,T) -> Bool) -> [T] { var array = elements for i in 0.. Date: Thu, 1 Nov 2018 06:55:11 +1100 Subject: [PATCH 61/86] Updated Run-Length Encoding to Swift 4.2 --- Run-Length Encoding/RLE.playground/Contents.swift | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Run-Length Encoding/RLE.playground/Contents.swift b/Run-Length Encoding/RLE.playground/Contents.swift index fc2d82505..8d6a0a403 100644 --- a/Run-Length Encoding/RLE.playground/Contents.swift +++ b/Run-Length Encoding/RLE.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - import Foundation let originalString = "aaaaabbbcdeeeeeeef" @@ -64,7 +59,7 @@ func testBufferWithoutSpans() -> Bool { // data ends up being longer. var bytes: [UInt8] = [] for i in 0..<1024 { - bytes.append(UInt8(i%256)) + bytes.append(UInt8(i % 256)) } return encodeAndDecode(bytes) } From d454cf1e1b3a9b60bc005a8b3051be1d328d1932 Mon Sep 17 00:00:00 2001 From: Randy the Dev <37282011+RandyTheDev@users.noreply.github.com> Date: Thu, 1 Nov 2018 07:25:19 +1100 Subject: [PATCH 62/86] Confirmed Linear Regression to work with Swift 4.2 --- .../LinearRegression.playground/Contents.swift | 7 +------ Linear Regression/README.markdown | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Linear Regression/LinearRegression.playground/Contents.swift b/Linear Regression/LinearRegression.playground/Contents.swift index 3e4135794..a093ef566 100644 --- a/Linear Regression/LinearRegression.playground/Contents.swift +++ b/Linear Regression/LinearRegression.playground/Contents.swift @@ -2,11 +2,6 @@ import Foundation -// last checked with Xcode 4.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - let carAge: [Double] = [10, 8, 3, 3, 2, 1] let carPrice: [Double] = [500, 400, 7000, 8500, 11000, 10500] var intercept = 0.0 @@ -22,7 +17,7 @@ let numberOfCarAdvertsWeSaw = carPrice.count let numberOfIterations = 100 let alpha = 0.0001 -for n in 1...numberOfIterations { +for _ in 1...numberOfIterations { for i in 0.. Date: Thu, 1 Nov 2018 07:35:17 +1100 Subject: [PATCH 63/86] Updated Minimum Edit Distance Playground for Swift 4.2 --- .../MinimumEditDistance.playground/Contents.swift | 12 ++++-------- Minimum Edit Distance/README.markdown | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Minimum Edit Distance/MinimumEditDistance.playground/Contents.swift b/Minimum Edit Distance/MinimumEditDistance.playground/Contents.swift index 967e73182..5db0aeb0d 100644 --- a/Minimum Edit Distance/MinimumEditDistance.playground/Contents.swift +++ b/Minimum Edit Distance/MinimumEditDistance.playground/Contents.swift @@ -1,15 +1,11 @@ // Minimum Edit Distance -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif extension String { public func minimumEditDistance(other: String) -> Int { - let m = self.characters.count - let n = other.characters.count + let m = self.count + let n = other.count var matrix = [[Int]](repeating: [Int](repeating: 0, count: n + 1), count: m + 1) // initialize matrix @@ -24,8 +20,8 @@ extension String { } // compute Levenshtein distance - for (i, selfChar) in self.characters.enumerated() { - for (j, otherChar) in other.characters.enumerated() { + for (i, selfChar) in self.enumerated() { + for (j, otherChar) in other.enumerated() { if otherChar == selfChar { // substitution of equal symbols with cost 0 matrix[i + 1][j + 1] = matrix[i][j] diff --git a/Minimum Edit Distance/README.markdown b/Minimum Edit Distance/README.markdown index b8880b2d4..c8e5e2f6d 100755 --- a/Minimum Edit Distance/README.markdown +++ b/Minimum Edit Distance/README.markdown @@ -37,8 +37,8 @@ Then in each cell the minimum of the cost of insertion, deletion, or substitutio ```swift // compute Levenshtein distance -for (i, selfChar) in self.characters.enumerated() { - for (j, otherChar) in other.characters.enumerated() { +for (i, selfChar) in self.enumerated() { + for (j, otherChar) in other.enumerated() { if otherChar == selfChar { // substitution of equal symbols with cost 0 matrix[i + 1][j + 1] = matrix[i][j] From eea4cfc6eaba53d86c3a383b1dce9c3c374b3ebd Mon Sep 17 00:00:00 2001 From: iillx Date: Wed, 31 Oct 2018 22:56:29 -0300 Subject: [PATCH 64/86] Counting Sort working with Swift 4.2 --- Counting Sort/CountingSort.playground/Contents.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Counting Sort/CountingSort.playground/Contents.swift b/Counting Sort/CountingSort.playground/Contents.swift index 4d918e384..dc375512a 100644 --- a/Counting Sort/CountingSort.playground/Contents.swift +++ b/Counting Sort/CountingSort.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - enum CountingSortError: Error { case arrayEmpty } From 43e76adfc53c5cadde2511e9fc80fa3c59114be9 Mon Sep 17 00:00:00 2001 From: iillx Date: Wed, 31 Oct 2018 23:10:55 -0300 Subject: [PATCH 65/86] Union Find working with Swift 4.2 and Xcode 10 --- Union-Find/UnionFind.playground/Contents.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Union-Find/UnionFind.playground/Contents.swift b/Union-Find/UnionFind.playground/Contents.swift index 6ac3b4c4e..b1f7fb4e1 100644 --- a/Union-Find/UnionFind.playground/Contents.swift +++ b/Union-Find/UnionFind.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - var dsu = UnionFindQuickUnion() for i in 1...10 { From 6707ce26934addaceff3d54ee417632e210443df Mon Sep 17 00:00:00 2001 From: iillx Date: Wed, 31 Oct 2018 23:16:04 -0300 Subject: [PATCH 66/86] Shunting Yard working fine with Swift 4.2 and Xcode 10 --- Shunting Yard/ShuntingYard.playground/Contents.swift | 5 ----- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 Shunting Yard/ShuntingYard.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Shunting Yard/ShuntingYard.playground/Contents.swift b/Shunting Yard/ShuntingYard.playground/Contents.swift index ddd73de59..38431f5e2 100644 --- a/Shunting Yard/ShuntingYard.playground/Contents.swift +++ b/Shunting Yard/ShuntingYard.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - internal enum OperatorAssociativity { case leftAssociative case rightAssociative diff --git a/Shunting Yard/ShuntingYard.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Shunting Yard/ShuntingYard.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Shunting Yard/ShuntingYard.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From a1d65fcba404f8a59897c46480e54cadbe491b63 Mon Sep 17 00:00:00 2001 From: iillx Date: Wed, 31 Oct 2018 23:25:54 -0300 Subject: [PATCH 67/86] Updated random number generation to Swift 4.2 --- Set Cover (Unweighted)/SetCover.playground/Contents.swift | 7 ++----- .../SetCover.playground/Sources/RandomArrayOfSets.swift | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Set Cover (Unweighted)/SetCover.playground/Contents.swift b/Set Cover (Unweighted)/SetCover.playground/Contents.swift index d61b9c84a..065f5fd4d 100644 --- a/Set Cover (Unweighted)/SetCover.playground/Contents.swift +++ b/Set Cover (Unweighted)/SetCover.playground/Contents.swift @@ -1,10 +1,5 @@ // SetCover -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif - let universe1 = Set(1...7) let array1 = randomArrayOfSets(covering: universe1) let cover1 = universe1.cover(within: array1) @@ -36,3 +31,5 @@ let emptySet = Set() let coverTest1 = emptySet.cover(within: array1) let coverTest2 = universe1.cover(within: Array>()) let coverTest3 = emptySet.cover(within: Array>()) + + diff --git a/Set Cover (Unweighted)/SetCover.playground/Sources/RandomArrayOfSets.swift b/Set Cover (Unweighted)/SetCover.playground/Sources/RandomArrayOfSets.swift index 9454c6383..ac4ff063e 100644 --- a/Set Cover (Unweighted)/SetCover.playground/Sources/RandomArrayOfSets.swift +++ b/Set Cover (Unweighted)/SetCover.playground/Sources/RandomArrayOfSets.swift @@ -14,10 +14,10 @@ public func randomArrayOfSets(covering universe: Set, while true { var generatedSet = Set() - let targetSetSize = Int(arc4random_uniform(UInt32(maxSetSize)) + 1) + let targetSetSize = Int.random(in: 0...maxSetSize) + 1 while true { - let randomUniverseIndex = Int(arc4random_uniform(UInt32(universe.count))) + let randomUniverseIndex = Int.random(in: 0...universe.count) for (setIndex, value) in universe.enumerated() { if setIndex == randomUniverseIndex { generatedSet.insert(value) From f37fb19f054c95b654e07186d5f6fc5cf56bb12d Mon Sep 17 00:00:00 2001 From: Bruno Scheele Date: Thu, 1 Nov 2018 20:55:17 +0100 Subject: [PATCH 68/86] Update README according to comments. --- Bloom Filter/README.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Bloom Filter/README.markdown b/Bloom Filter/README.markdown index 4364db857..5f2ede069 100644 --- a/Bloom Filter/README.markdown +++ b/Bloom Filter/README.markdown @@ -102,7 +102,9 @@ If you're coming from another imperative language, you might notice the unusual ## Another approach -Another approach to create different hashes of an element for use in the Bloom filter, is to use the same hash function for every iteration, but combine it with different random numbers. This can help, because finding good hashing functions is hard, but combining them is equally non-trivial. +In the previous section, you learnt about how using multiple different hash functions can help reduce the chance of collisions in the bloom filter. However, good hash functions are difficult to design. A simple alternative to multiple hash functions is to use a set of random numbers. + +As an example, let's say a bloom filter wants to hash each element 15 times during insertion. Instead of using 15 different hash functions, you can rely on just one hash function. The hash value can then be combined with 15 different values to form the indices for flipping. This bloom filter would initialize a set of 15 random numbers ahead of time and use these values during each insertion. ``` hash("Hello world!") >> hash(987654321) // would flip bit 8 From f9133844436bd6336595e0f6b66038f676dd3b3a Mon Sep 17 00:00:00 2001 From: gmotzespina Date: Mon, 5 Nov 2018 19:00:34 -0600 Subject: [PATCH 69/86] Swift 4.2 Migration #748 - Depth First Search migrated to Swift 4.2 --- .../APSP/APSP.xcodeproj/project.pbxproj | 8 +++++--- .../Pages/Simple Example.xcplaygroundpage/Contents.swift | 5 +---- Depth-First Search/Tests/Tests.xcodeproj/project.pbxproj | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/All-Pairs Shortest Paths/APSP/APSP.xcodeproj/project.pbxproj b/All-Pairs Shortest Paths/APSP/APSP.xcodeproj/project.pbxproj index 78df3fb76..908d32785 100644 --- a/All-Pairs Shortest Paths/APSP/APSP.xcodeproj/project.pbxproj +++ b/All-Pairs Shortest Paths/APSP/APSP.xcodeproj/project.pbxproj @@ -196,7 +196,7 @@ }; 493D8DF01CDD5B960089795A = { CreatedOnToolsVersion = 7.3; - LastSwiftMigration = 0820; + LastSwiftMigration = 1010; }; }; }; @@ -420,7 +420,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.swift-algorithm-club.APSP"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.2; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -442,7 +443,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.swift-algorithm-club.APSP"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.2; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; diff --git a/Depth-First Search/DepthFirstSearch.playground/Pages/Simple Example.xcplaygroundpage/Contents.swift b/Depth-First Search/DepthFirstSearch.playground/Pages/Simple Example.xcplaygroundpage/Contents.swift index 99f20a729..c83f52af8 100644 --- a/Depth-First Search/DepthFirstSearch.playground/Pages/Simple Example.xcplaygroundpage/Contents.swift +++ b/Depth-First Search/DepthFirstSearch.playground/Pages/Simple Example.xcplaygroundpage/Contents.swift @@ -1,7 +1,4 @@ -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif +// last checked with Xcode 10.1 func depthFirstSearch(_ graph: Graph, source: Node) -> [String] { var nodesExplored = [source.label] diff --git a/Depth-First Search/Tests/Tests.xcodeproj/project.pbxproj b/Depth-First Search/Tests/Tests.xcodeproj/project.pbxproj index 8f6058600..2b433bd96 100644 --- a/Depth-First Search/Tests/Tests.xcodeproj/project.pbxproj +++ b/Depth-First Search/Tests/Tests.xcodeproj/project.pbxproj @@ -234,7 +234,7 @@ PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -247,7 +247,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; From 0f739b5230f7fe0df655fac82941e9111d346b90 Mon Sep 17 00:00:00 2001 From: gmotzespina Date: Mon, 5 Nov 2018 19:08:43 -0600 Subject: [PATCH 70/86] Swift 4.2 support Depth-First Search --- .../DepthFirstSearch.playground/Edge.o | Bin 0 -> 7016 bytes .../DepthFirstSearch.playground/Graph.o | Bin 0 -> 21488 bytes .../DepthFirstSearch.playground/Node.o | Bin 0 -> 19288 bytes .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ .../xcshareddata/WorkspaceSettings.xcsettings | 8 ++++++++ 5 files changed, 16 insertions(+) create mode 100644 Depth-First Search/DepthFirstSearch.playground/Edge.o create mode 100644 Depth-First Search/DepthFirstSearch.playground/Graph.o create mode 100644 Depth-First Search/DepthFirstSearch.playground/Node.o create mode 100644 swift-algorithm-club.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 swift-algorithm-club.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/Depth-First Search/DepthFirstSearch.playground/Edge.o b/Depth-First Search/DepthFirstSearch.playground/Edge.o new file mode 100644 index 0000000000000000000000000000000000000000..ab1e89b3aa83ed547413ba061a5edfd5dc918137 GIT binary patch literal 7016 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 literal 0 HcmV?d00001 diff --git a/Depth-First Search/DepthFirstSearch.playground/Graph.o b/Depth-First Search/DepthFirstSearch.playground/Graph.o new file mode 100644 index 0000000000000000000000000000000000000000..dde35fb0f1a416f1a99b083ab8937861bd8038af GIT binary patch literal 21488 zcmdUX4|H5db@#KeV+G5y2oOxbWFe+8A+{yQ{}Pg-wY>IIBE_;-vR&eIwU$=WCac{= zyK74ZwQIx{J-=)#dQj_A(pLRL>$aGxr*)4K&_OY7EK*2R4kT{-rHJp)Rw1TUIR#8g zP=CLf`*zYYbz>8w~t|5AKcW8}N@0 zA6#$8XMVN1E&I=g&ANDwGPtU4*GN75+@wh(6iP=1(n0`2p|-%Wwj%A^J`>IV&)?=R(&M7X$4=qO`V518JhsCy-ogUU6$*8x(*4nR zkCc1uo4!R?tP_3X@7DG?YF0Wo1^LveXm@%?C_R{r^hdhA`o8)O&G?A$UwDtcxeoh8 zSFKbj2!%vnXE>S8^hdn<_PkSb*NM=E+q9mlorWQy@#yPJ#8c@)6JG!IioUDDVL~7M zw+H%s1*zf<{O8eE8sCPEn)i~3_%?~YU6u5mNTrJEm&CVL##xobgRC4c&gCjrMWImQ z#3P+WBfb5tdY6`*6b18+eY*?(b5x5yi3egE!^rW*V_Niy?~U>ImWY$^#6$FTM3sXP=&KU5E{nc%&?kN@uaDyyf$`dRP4qc2 z_=@P8guZ3QbEq%T)f-OrLSJ+9krpuqups&zBW9QSugHu$C%&<8Diw>S(%$$Qw`z8$ zzjM&X@jL_jWUM$%DMry3?F;urqVev8S6`J!-~3YhJo-8leaUcVI+Tf@ipCM&=6%{C z{co-4%hD)Z3u50a?30*_8+Cms6zL6h_lNr;4qZCmM&F~$2P7cL_v!xXQo~q_q2t^W zx8t(`AJxc;Y8I)BG|MOU7{+73q#wByNgeV=D?YrC8q^0Y#zXkj2=rSA2& zew-pozrP(V>@lsOt58)C1Lu|6C*BPnw%45RLqq>URbZMfsW7gHG*` zm^FNPkN@F^zqI~Vj2P7)>xYUJW{i^dx3@M8{}t6#O{(@THCz9RRu;6v{99=#I=2AZ ztEj2Fd+QSWH`GsCSCqgL^sn{o6I{OOiJ=8LisDu~e0E7OHCcb9wGUt3pp7f~1Kxl! zt5vJR*A4Xfdgc~0e;+4=7NX;Iy)|?ls;}37*?I=n)zUUzCH6sI2dsMvaY3&Tjut0g zL-53k!cT|FBT48?hu1Z?8SIEbL|{DtBoF-Q3EP74dW+ae8Co!2hPJ%rx`HX;IjKr z7&xb!VXxtNJ21)N>$VkLzXIL~XdG>}UIN>Q(@AL|&&WLuo)I*X)s=be_S|&(rk4#< zC@VLxxVZT8%9jtDwz@?)o-^%sSlbTQ=8~ut@yt~-KQ!BH2cUDR7v;^gBF8(^8tYI6 zmoPY>h*FEQFn!cKbD8eoIFb2Sr(9#}kvaT|fl+oHjltfQ`HVTa2yPjT@HlD^TbPrtOF5yq;0+O+RMkIq4^$@&H?z+GT;@lZ#getI7UXkMA5qGDQk z`d)XNtw(9>A%wL?Ixp7B{TE?f&DG4P1+^D)68!6P=Q@SXZEf(ci zjnVR(*vsgZ?wKdlfU%y3rv^}o1qqptH~CmWPABXME(6HbPA0#olvy{J){!dMNk?Jm znD*gb4xg{VTSx%yt7^0fbLOoYsz5RLCv{esvxVZ4)PzMiN$y)PD16O~}BL((40yZyM z=3v_i_A&O*x`eUD$Tr)bDFmb0`j$ETBcs{+OsnF_nSk}VPs6tmCxNk{#d8gyWXKHZ zYXc22|8Ri!RhTa;1v7=4`oFa7&}fEjD9w2tkl&289Jl@>D;j9q`V#E9HN zfwsqla~?&eHH+Yr8EY~VrvEq-yk0*gF8Mh}cKuqlzbv<(yA2|GyQrpL`+|7ylId*h z+SSHRHg$#dw$-%PnAW|UASE4Iwdv

oMAESZ;sNUa~*XDf_D99<-W46eQ|}%>q)l zXS0BkN}C1b_!)S42F7!*@7|BTmi@0)FZ-Wb)3ZPR@ARiSpKPGx?FM9qSGmaVG3{Su zc0z7iSbPD=WdU~>R?aRchuLdAJ*f^T zJnN{~^MKSK=do5;(qw09o9y-tus{Z9;q9?eF-G>#gto$+)1T3c z*t1|hZ(7e|!v|;|Z$@@6o+U29_Y*43+e1(}0N>Etqu`XYgH{PPELQE%5RhX7)VLN2 zEJM%&=^r9V4KP7k?!D^Jw6>4CcK68uIr>;3jp_vkD+@YwQR%RC%C(+qwj)|Y)9{ZC zsAz@I`rLc<5<&t=R~7}cpbyKVcx7nbxxtvrlLJEluFEy3TeTAt4vt8@GqZAas`fex zXe5kc0k$uWGA9A!td0c^>NYEZybqvuP`p9$2EfZbFB|;N%&&gvja*s3Wm+q)_&IK| z74>i6%@sfMFUhKYV*bAGkTt*Vj{r~d`HJ=YlXnCB*6fqyw8q{7)%)x`L0PqaEmje> z$7Bxolq7TQp?sCY%ngJ{dB(rW51VyZs=b0dLo zs{6BnZ(=-e<{WnBAJ>Z}d#D!YT|Hk)CoBwcrcvR*UsxZQADx-2^n3Cz>-F=NW(%pr z$v@0J|JTH{Y_=lvBY}Tr`pMjM7B{fF$@&URRL@YDh>B?j{c|20*i2P{>4p((pd;8E zYj*v7rPTZi`DV_s8fsoU-_)A_MfqR+apu}2vj^5>oOE=It^{TMYw|80PNH2kt@N2och{b(1-Elgh3fvLZMZY@PSU~Y z*|gWINtCNX4Gv5=?oWeZhU3e$mbj>pV4SR}&u@7o|2!W(O!DIh1b3lYY1tzk)`KzGs7_NE_mTRH zXJ2H2D^ZR+Y9>)Gp+1KeCJHUEReOpwEIqG)ZsDB{^>~5R#?eXl@Epoi4|xN*Q2=_l zRxb;rknPzw(|(iEqKOb*v!FAo^*KXMOnJydP(NfxyW@fYTVy5ws)_1zQC9TWKQiOPT1RnYxVJkb@o$7lE=T|JQ$ZXPaaa$9>U z(x2Ma)0aq}j--;&czD~sNb1paBDqa{iMAyi>q+!S)4hFLI%Am=s7$7Nx9pGhr_#P) zB;4QGtBX{LF4&rkg$H~36Pb9|wqPRD-x*15JJ26a_HI=gOPV*@EE6&Iht_gV$r%>=3H$K#}edoF&^3MA~ zY_AHREIzbPJxv8V*XwOh4}3?OZC9)I={v^ryu2qt-;(QBI&c2^g~?Ao_W6IUf5%(b zZhxsLX&4>O%P1&3sw>=GQ6(L^+;|lD24lsN`dO*3(YU03PU`t=ww%0AB+Lr+(^CJt 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 literal 0 HcmV?d00001 diff --git a/Depth-First Search/DepthFirstSearch.playground/Node.o b/Depth-First Search/DepthFirstSearch.playground/Node.o new file mode 100644 index 0000000000000000000000000000000000000000..1090b3a9cbf150965dc206734fec12c24cda0982 GIT binary patch literal 19288 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 WO2$%2gh>zf&_PY60#Acy_5T4cZe^PQ literal 0 HcmV?d00001 diff --git a/swift-algorithm-club.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/swift-algorithm-club.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/swift-algorithm-club.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/swift-algorithm-club.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/swift-algorithm-club.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 000000000..08de0be8d --- /dev/null +++ b/swift-algorithm-club.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded + + + From 07732e85027602ed909f9afbd9ebb2869ba18632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Salda=C3=B1a?= Date: Mon, 5 Nov 2018 19:18:53 -0600 Subject: [PATCH 71/86] fix deprecated methods and return type --- .../BoyerMooreHorspool.playground/Contents.swift | 10 +++++----- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ .../BoyerMooreHorspool.playground/timeline.xctimeline | 6 +++--- Boyer-Moore-Horspool/BoyerMooreHorspool.swift | 10 +++++----- 4 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 Boyer-Moore-Horspool/BoyerMooreHorspool.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift index e88a1b93d..c51070caf 100644 --- a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift +++ b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift @@ -13,16 +13,16 @@ http://www.drdobbs.com/database/faster-string-searches/184408171 */ extension String { - func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Index? { + func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Int? { // Cache the length of the search pattern because we're going to // use it a few times and it's expensive to calculate. - let patternLength = pattern.characters.count - guard patternLength > 0, patternLength <= characters.count else { return nil } + let patternLength = pattern.count + guard patternLength > 0, patternLength <= self.count else { return nil } // Make the skip table. This table determines how far we skip ahead // when a character from the pattern is found. var skipTable = [Character: Int]() - for (i, c) in pattern.characters.enumerated() { + for (i, c) in pattern.enumerated() { skipTable[c] = patternLength - i - 1 } @@ -57,7 +57,7 @@ extension String { if c == lastChar { // There is a possible match. Do a brute-force search backwards. - if let k = backwards() { return k } + if let k = backwards() { return k.encodedOffset } if !usingHorspoolImprovement { // If no match, we can only safely skip one character ahead. diff --git a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/timeline.xctimeline b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/timeline.xctimeline index 89bc76f90..431d4a349 100644 --- a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/timeline.xctimeline +++ b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/timeline.xctimeline @@ -3,17 +3,17 @@ version = "3.0"> diff --git a/Boyer-Moore-Horspool/BoyerMooreHorspool.swift b/Boyer-Moore-Horspool/BoyerMooreHorspool.swift index af8aea9d9..92d2ee4c1 100644 --- a/Boyer-Moore-Horspool/BoyerMooreHorspool.swift +++ b/Boyer-Moore-Horspool/BoyerMooreHorspool.swift @@ -6,16 +6,16 @@ http://www.drdobbs.com/database/faster-string-searches/184408171 */ extension String { - func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Index? { + func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Int? { // Cache the length of the search pattern because we're going to // use it a few times and it's expensive to calculate. - let patternLength = pattern.characters.count - guard patternLength > 0, patternLength <= characters.count else { return nil } + let patternLength = pattern.count + guard patternLength > 0, patternLength <= self.count else { return nil } // Make the skip table. This table determines how far we skip ahead // when a character from the pattern is found. var skipTable = [Character: Int]() - for (i, c) in pattern.characters.enumerated() { + for (i, c) in pattern.enumerated() { skipTable[c] = patternLength - i - 1 } @@ -50,7 +50,7 @@ extension String { if c == lastChar { // There is a possible match. Do a brute-force search backwards. - if let k = backwards() { return k } + if let k = backwards() { return k.encodedOffset } if !usingHorspoolImprovement { // If no match, we can only safely skip one character ahead. From 17990d8b52ae03bae0570f5e97e18d5f75485136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Salda=C3=B1a?= Date: Mon, 5 Nov 2018 19:37:55 -0600 Subject: [PATCH 72/86] change return type --- .../BoyerMooreHorspool.playground/Contents.swift | 4 ++-- .../BoyerMooreHorspool.playground/timeline.xctimeline | 6 +++--- Boyer-Moore-Horspool/BoyerMooreHorspool.swift | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift index c51070caf..eba2a5806 100644 --- a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift +++ b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift @@ -13,7 +13,7 @@ http://www.drdobbs.com/database/faster-string-searches/184408171 */ extension String { - func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Int? { + func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Index? { // Cache the length of the search pattern because we're going to // use it a few times and it's expensive to calculate. let patternLength = pattern.count @@ -57,7 +57,7 @@ extension String { if c == lastChar { // There is a possible match. Do a brute-force search backwards. - if let k = backwards() { return k.encodedOffset } + if let k = backwards() { return k } if !usingHorspoolImprovement { // If no match, we can only safely skip one character ahead. diff --git a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/timeline.xctimeline b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/timeline.xctimeline index 431d4a349..5eb7f2337 100644 --- a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/timeline.xctimeline +++ b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/timeline.xctimeline @@ -3,17 +3,17 @@ version = "3.0"> diff --git a/Boyer-Moore-Horspool/BoyerMooreHorspool.swift b/Boyer-Moore-Horspool/BoyerMooreHorspool.swift index 92d2ee4c1..1dd37873a 100644 --- a/Boyer-Moore-Horspool/BoyerMooreHorspool.swift +++ b/Boyer-Moore-Horspool/BoyerMooreHorspool.swift @@ -6,7 +6,7 @@ http://www.drdobbs.com/database/faster-string-searches/184408171 */ extension String { - func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Int? { + func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Index? { // Cache the length of the search pattern because we're going to // use it a few times and it's expensive to calculate. let patternLength = pattern.count @@ -50,7 +50,7 @@ extension String { if c == lastChar { // There is a possible match. Do a brute-force search backwards. - if let k = backwards() { return k.encodedOffset } + if let k = backwards() { return k } if !usingHorspoolImprovement { // If no match, we can only safely skip one character ahead. From a7047d8bbb8cbdc023c8979dcfa22d15ba6ed21f Mon Sep 17 00:00:00 2001 From: Morgan Davison Date: Tue, 6 Nov 2018 20:09:29 -0500 Subject: [PATCH 73/86] Compile for Swift 4.2 --- B-Tree/BTree.playground/Contents.swift | 5 +--- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++++ B-Tree/Tests/Tests.xcodeproj/project.pbxproj | 24 +++++++++++++++---- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++++ .../xcshareddata/xcschemes/Tests.xcscheme | 2 +- 5 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 B-Tree/BTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 B-Tree/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/B-Tree/BTree.playground/Contents.swift b/B-Tree/BTree.playground/Contents.swift index a0643586f..f6325513a 100644 --- a/B-Tree/BTree.playground/Contents.swift +++ b/B-Tree/BTree.playground/Contents.swift @@ -2,10 +2,7 @@ import Foundation -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif +// last checked with Xcode 10.0 let bTree = BTree(order: 1)! diff --git a/B-Tree/BTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/B-Tree/BTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/B-Tree/BTree.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/B-Tree/Tests/Tests.xcodeproj/project.pbxproj b/B-Tree/Tests/Tests.xcodeproj/project.pbxproj index 3e12b9ac3..66eb85190 100644 --- a/B-Tree/Tests/Tests.xcodeproj/project.pbxproj +++ b/B-Tree/Tests/Tests.xcodeproj/project.pbxproj @@ -85,12 +85,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 1000; ORGANIZATIONNAME = "Viktor Szilárd Simkó"; TargetAttributes = { C66702771D0EEE25008CD769 = { CreatedOnToolsVersion = 7.3.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 1000; }; }; }; @@ -144,14 +144,22 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -192,14 +200,22 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -234,7 +250,7 @@ PRODUCT_BUNDLE_IDENTIFIER = viktorsimko.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -247,7 +263,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = viktorsimko.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/B-Tree/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/B-Tree/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/B-Tree/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/B-Tree/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme b/B-Tree/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme index 9d6c542ae..d1555acfb 100644 --- a/B-Tree/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme +++ b/B-Tree/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme @@ -1,6 +1,6 @@ Date: Wed, 7 Nov 2018 22:38:11 -0800 Subject: [PATCH 74/86] Added Markdown Documentation to Stack playground This might be overkill for such a small file, but I wish I started using Swift Markdown early in my iOS career. Option click is too convenient to ignore! --- Stack/Stack.playground/Contents.swift | 28 +++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Stack/Stack.playground/Contents.swift b/Stack/Stack.playground/Contents.swift index 1eb705f20..13774d7d1 100644 --- a/Stack/Stack.playground/Contents.swift +++ b/Stack/Stack.playground/Contents.swift @@ -1,4 +1,4 @@ -/* +/** Stack A stack is like an array but with limited functionality. You can only push @@ -9,27 +9,51 @@ last is the first one to come off with the next pop. Push and pop are O(1) operations. + + ## Usage + ``` + var myStack = Stack(array: []) + myStack.push(10) + myStack.push(3) + myStack.push(57) + myStack.pop() // 57 + myStack.pop() // 3 + ``` */ - public struct Stack { + + /// Datastructure consisting of a generic item. fileprivate var array = [T]() + /// The number of items in the stack. public var count: Int { return array.count } + /// Verifies if the stack is empty. public var isEmpty: Bool { return array.isEmpty } + /** + Pushes an item to the top of the stack. + + - Parameter element: The item being pushed. + */ public mutating func push(_ element: T) { array.append(element) } + /** + Removes and returns the item at the top of the sack. + + - Returns: The item at the top of the stack. + */ public mutating func pop() -> T? { return array.popLast() } + /// Returns the item at the top of the stack. public var top: T? { return array.last } From eb228cc1d18d860ad825c7d79063524121555bce Mon Sep 17 00:00:00 2001 From: Kelvin Reid Date: Sun, 11 Nov 2018 21:24:07 -0500 Subject: [PATCH 75/86] [Swift 4.2] Updated Hash Set --- Hash Set/HashSet.playground/Contents.swift | 4 ---- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 Hash Set/HashSet.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 swift-algorithm-club.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Hash Set/HashSet.playground/Contents.swift b/Hash Set/HashSet.playground/Contents.swift index 5edb76bb4..551c6dc86 100644 --- a/Hash Set/HashSet.playground/Contents.swift +++ b/Hash Set/HashSet.playground/Contents.swift @@ -1,8 +1,4 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif var set = HashSet() diff --git a/Hash Set/HashSet.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Hash Set/HashSet.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Hash Set/HashSet.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/swift-algorithm-club.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/swift-algorithm-club.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/swift-algorithm-club.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From 67ecddaafb2e7637da0b24787ece79cadd82603c Mon Sep 17 00:00:00 2001 From: Kelvin Reid Date: Sun, 11 Nov 2018 21:37:44 -0500 Subject: [PATCH 76/86] [Swift 4.2] Updated Hash Table --- Hash Table/HashTable.playground/Contents.swift | 3 --- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 Hash Table/HashTable.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Hash Table/HashTable.playground/Contents.swift b/Hash Table/HashTable.playground/Contents.swift index 273113440..121fb6032 100644 --- a/Hash Table/HashTable.playground/Contents.swift +++ b/Hash Table/HashTable.playground/Contents.swift @@ -1,8 +1,5 @@ //: Playground - noun: a place where people can play -#if swift(>=4.0) -print("Hello, Swift 4!") -#endif // Playing with hash values "firstName".hashValue diff --git a/Hash Table/HashTable.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Hash Table/HashTable.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Hash Table/HashTable.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From 70d26fccdea4e655986b0fe36cec2d2dae2ab8e8 Mon Sep 17 00:00:00 2001 From: Kelvin Reid Date: Sun, 11 Nov 2018 21:44:55 -0500 Subject: [PATCH 77/86] [Swift 4.2] Updated Heap Sort --- Heap Sort/Tests/HeapSortTests.swift | 6 ---- .../Tests/Tests.xcodeproj/project.pbxproj | 31 +++++++++++++------ .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++ .../xcshareddata/xcschemes/Tests.xcscheme | 4 +-- 4 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 Heap Sort/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Heap Sort/Tests/HeapSortTests.swift b/Heap Sort/Tests/HeapSortTests.swift index b36f605e3..dae1f8a68 100644 --- a/Heap Sort/Tests/HeapSortTests.swift +++ b/Heap Sort/Tests/HeapSortTests.swift @@ -1,12 +1,6 @@ import XCTest class HeapSortTests: XCTestCase { - func testSwift4() { - // last checked with Xcode 9.0b4 - #if swift(>=4.0) - print("Hello, Swift 4!") - #endif - } func testSort() { var h1 = Heap(array: [5, 13, 2, 25, 7, 17, 20, 8, 4], sort: >) diff --git a/Heap Sort/Tests/Tests.xcodeproj/project.pbxproj b/Heap Sort/Tests/Tests.xcodeproj/project.pbxproj index ff1f4937f..62e6d4e3f 100644 --- a/Heap Sort/Tests/Tests.xcodeproj/project.pbxproj +++ b/Heap Sort/Tests/Tests.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 51; objects = { /* Begin PBXBuildFile section */ @@ -86,17 +86,17 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1010; ORGANIZATIONNAME = "Swift Algorithm Club"; TargetAttributes = { 7B2BBC7F1C779D720067B71D = { CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 0820; + LastSwiftMigration = 1010; }; }; }; buildConfigurationList = 7B2BBC6C1C779D710067B71D /* Build configuration list for PBXProject "Tests" */; - compatibilityVersion = "Xcode 3.2"; + compatibilityVersion = "Xcode 10.0"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( @@ -149,12 +149,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -201,12 +203,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -230,7 +234,8 @@ MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; }; name = Release; }; @@ -239,10 +244,14 @@ buildSettings = { COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -251,10 +260,14 @@ buildSettings = { COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/Heap Sort/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Heap Sort/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Heap Sort/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Heap Sort/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme b/Heap Sort/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme index 538a6f4fa..1608804f9 100644 --- a/Heap Sort/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme +++ b/Heap Sort/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme @@ -1,6 +1,6 @@ Date: Sun, 11 Nov 2018 21:49:37 -0500 Subject: [PATCH 78/86] [Swift 4.2] Updated Heap --- Heap/Tests/HeapTests.swift | 7 ----- Heap/Tests/Tests.xcodeproj/project.pbxproj | 31 +++++++++++++------ .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++ .../xcshareddata/xcschemes/Tests.xcscheme | 4 +-- 4 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 Heap/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Heap/Tests/HeapTests.swift b/Heap/Tests/HeapTests.swift index 1ed15c726..ecf143778 100755 --- a/Heap/Tests/HeapTests.swift +++ b/Heap/Tests/HeapTests.swift @@ -7,13 +7,6 @@ import XCTest class HeapTests: XCTestCase { - func testSwift4() { - // last checked with Xcode 9.0b4 - #if swift(>=4.0) - print("Hello, Swift 4!") - #endif - } - fileprivate func verifyMaxHeap(_ h: Heap) -> Bool { for i in 0.. + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Heap/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme b/Heap/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme index 77d01bebc..1608804f9 100755 --- a/Heap/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme +++ b/Heap/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme @@ -1,6 +1,6 @@ Date: Sun, 11 Nov 2018 23:00:22 -0500 Subject: [PATCH 79/86] Update Contents.swift --- HaversineDistance/HaversineDistance.playground/Contents.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/HaversineDistance/HaversineDistance.playground/Contents.swift b/HaversineDistance/HaversineDistance.playground/Contents.swift index 7aa686645..3d8d60f54 100644 --- a/HaversineDistance/HaversineDistance.playground/Contents.swift +++ b/HaversineDistance/HaversineDistance.playground/Contents.swift @@ -1,8 +1,4 @@ import UIKit -// last checked with Xcode 9.04 -#if swift(>=4) -print("Hello, Swift 4!") -#endif func haversineDinstance(la1: Double, lo1: Double, la2: Double, lo2: Double, radius: Double = 6367444.7) -> Double { From ef4e890fd9f5b0ddf15cfa289fc2993ee46a9e04 Mon Sep 17 00:00:00 2001 From: Kelvin Lau Date: Sun, 11 Nov 2018 23:01:46 -0500 Subject: [PATCH 80/86] Updates Contents.swift --- .../BoyerMooreHorspool.playground/Contents.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift index 5817cc41f..1666549c1 100644 --- a/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift +++ b/Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.0) - print("Hello, Swift 4!") -#endif - /* Boyer-Moore string search From 9ba8b54dc580cc6cb3803a1a2cd2a9efcd5bf6ab Mon Sep 17 00:00:00 2001 From: gmotzespina Date: Mon, 12 Nov 2018 19:53:38 -0600 Subject: [PATCH 81/86] Bubble Sort Readme Code Issue #838 solved --- Bubble Sort/README.markdown | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Bubble Sort/README.markdown b/Bubble Sort/README.markdown index e55129d93..648b9f324 100644 --- a/Bubble Sort/README.markdown +++ b/Bubble Sort/README.markdown @@ -57,9 +57,9 @@ This is the same for the forth and fifth passes. ```swift for i in 0.. Date: Tue, 27 Nov 2018 14:22:02 -0600 Subject: [PATCH 82/86] Removing version check --- Tree/Tree.playground/Contents.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Tree/Tree.playground/Contents.swift b/Tree/Tree.playground/Contents.swift index 06f992fa8..1fad157a0 100644 --- a/Tree/Tree.playground/Contents.swift +++ b/Tree/Tree.playground/Contents.swift @@ -1,10 +1,5 @@ //: Playground - noun: a place where people can play -// last checked with Xcode 9.0b4 -#if swift(>=4.2) -print("Hello, Swift 4.2!") -#endif - let tree = TreeNode(value: "beverages") let hotNode = TreeNode(value: "hot") From f1363dd983ccacf1e48d9d393022f3ce68ba3c39 Mon Sep 17 00:00:00 2001 From: Francesco Scalise Date: Tue, 4 Dec 2018 19:31:26 +0100 Subject: [PATCH 83/86] [Swift 4.2] Count occurences --- Count Occurrences/CountOccurrences.playground/Contents.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Count Occurrences/CountOccurrences.playground/Contents.swift b/Count Occurrences/CountOccurrences.playground/Contents.swift index 6138b74ac..a34e3485f 100644 --- a/Count Occurrences/CountOccurrences.playground/Contents.swift +++ b/Count Occurrences/CountOccurrences.playground/Contents.swift @@ -1,7 +1,3 @@ -// last checked with Xcode 9.0b4 -#if swift(>=4.0) - print("Hello, Swift 4!") -#endif func countOccurrencesOfKey(_ key: Int, inArray a: [Int]) -> Int { func leftBoundary() -> Int { From 1f15eda576530fdf76bb8245eecb99a5b4233a48 Mon Sep 17 00:00:00 2001 From: Andrzej Michnia Date: Sun, 16 Dec 2018 22:44:30 +0100 Subject: [PATCH 84/86] Fixed error in description --- Comb Sort/README.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Comb Sort/README.markdown b/Comb Sort/README.markdown index d30d429b3..20c939307 100644 --- a/Comb Sort/README.markdown +++ b/Comb Sort/README.markdown @@ -64,8 +64,8 @@ This will sort the values of the array into ascending order -- increasing in val ## Performance Comb Sort was created to improve upon the worst case time complexity of Bubble Sort. With Comb -Sort, the worst case scenario for performance is exponential -- O(n^2). At best though, Comb Sort -performs at O(n logn) time complexity. This creates a drastic improvement over Bubble Sort's performance. +Sort, the worst case scenario for performance is polynomial -- O(n^2). At best though, Comb Sort +performs at O(n logn) time complexity -- loglinear. This creates a drastic improvement over Bubble Sort's performance. Similar to Bubble Sort, the space complexity for Comb Sort is constant -- O(1). This is extremely space efficient as it sorts the array in place. From a9c311588b2ecee2420af4cfee91217db427f450 Mon Sep 17 00:00:00 2001 From: Mac Bellingrath Date: Wed, 26 Dec 2018 15:27:08 -0500 Subject: [PATCH 85/86] Update README.md --- Convex Hull/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Convex Hull/README.md b/Convex Hull/README.md index d27027a45..ab263f00d 100644 --- a/Convex Hull/README.md +++ b/Convex Hull/README.md @@ -2,7 +2,7 @@ Given a group of points on a plane. The Convex Hull algorithm calculates the shape (made up from the points itself) containing all these points. It can also be used on a collection of points of different dimensions. This implementation however covers points on a plane. It essentially calculates the lines between points which together contain all points. In comparing different solutions to this problem we can describe each algorithm in terms of it's big-O time complexity. -There are multiple Convex Hull algorithms but this solution is called Quickhull, is comes from the work of both W. Eddy in 1977 and also separately A. Bykat in 1978, this algorithm has an expected time complexity of O(n log n), but it's worst-case time-complexity can be O(n^2) . With average conditions the algorithm has ok efficiency, but it's time-complexity can start to head become more exponential in cases of high symmetry or where there are points lying on the circumference of a circle for example. +There are multiple Convex Hull algorithms but this solution is called Quickhull, is comes from the work of both W. Eddy in 1977 and also separately A. Bykat in 1978, this algorithm has an expected time complexity of O(n log n), but it's worst-case time-complexity can be O(n^2) . With average conditions the algorithm has ok efficiency, but it's time-complexity can start to become more exponential in cases of high symmetry or where there are points lying on the circumference of a circle for example. ## Quickhull From c1b704dfbe27b96a67a34949055bcc55a47ca7c3 Mon Sep 17 00:00:00 2001 From: Mac Bellingrath Date: Thu, 27 Dec 2018 09:14:45 -0500 Subject: [PATCH 86/86] Update README.md --- Convex Hull/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Convex Hull/README.md b/Convex Hull/README.md index d27027a45..71a470f56 100644 --- a/Convex Hull/README.md +++ b/Convex Hull/README.md @@ -17,7 +17,7 @@ The quickhull algorithm works as follows: - Keep on doing so on until no more points are left, the recursion has come to an end and the points selected constitute the convex hull. -Our functioni will have the following defininition: +Our function will have the following defininition: `findHull(points: [CGPoint], p1: CGPoint, p2: CGPoint)`