Skip to content

Commit

Permalink
Update Z-Algorithm up to Swift 4.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
artFintch committed Oct 4, 2018
1 parent 4d50254 commit 7442c10
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
5 changes: 2 additions & 3 deletions Z-Algorithm/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ This a simple description of the idea that is behind this algorithm. There are a
Here is the code of the function that computes the Z-array:
```swift
func ZetaAlgorithm(ptrn: String) -> [Int]? {

let pattern = Array(ptrn.characters)
let pattern = Array(ptrn)
let patternLength: Int = pattern.count

guard patternLength > 0 else {
Expand Down Expand Up @@ -131,7 +130,7 @@ The Z-Algorithm discussed above leads to the simplest linear-time string matchin
extension String {

func indexesOf(pattern: String) -> [Int]? {
let patternLength: Int = pattern.characters.count
let patternLength: Int = pattern.count
/* Let's calculate the Z-Algorithm on the concatenation of pattern and text */
let zeta = ZetaAlgorithm(ptrn: pattern + "💲" + self)

Expand Down
3 changes: 1 addition & 2 deletions Z-Algorithm/ZAlgorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import Foundation

func ZetaAlgorithm(ptrn: String) -> [Int]? {

let pattern = Array(ptrn.characters)
let pattern = Array(ptrn)
let patternLength = pattern.count

guard patternLength > 0 else {
Expand Down
10 changes: 2 additions & 8 deletions Z-Algorithm/ZetaAlgorithm.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
//: Playground - noun: a place where people can play

// last checked with Xcode 9.0b4
#if swift(>=4.0)
print("Hello, Swift 4!")
#endif

func ZetaAlgorithm(ptrn: String) -> [Int]? {

let pattern = Array(ptrn.characters)
let pattern = Array(ptrn)
let patternLength = pattern.count

guard patternLength > 0 else {
Expand Down Expand Up @@ -65,7 +59,7 @@ func ZetaAlgorithm(ptrn: String) -> [Int]? {
extension String {

func indexesOf(pattern: String) -> [Int]? {
let patternLength = pattern.characters.count
let patternLength = pattern.count
let zeta = ZetaAlgorithm(ptrn: pattern + "💲" + self)

guard zeta != nil else {
Expand Down
2 changes: 1 addition & 1 deletion Z-Algorithm/ZetaAlgorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
extension String {

func indexesOf(pattern: String) -> [Int]? {
let patternLength = pattern.characters.count
let patternLength = pattern.count
let zeta = ZetaAlgorithm(ptrn: pattern + "💲" + self)

guard zeta != nil else {
Expand Down

0 comments on commit 7442c10

Please sign in to comment.