Skip to content

Commit 7442c10

Browse files
committed
Update Z-Algorithm up to Swift 4.2.
1 parent 4d50254 commit 7442c10

File tree

4 files changed

+6
-14
lines changed

4 files changed

+6
-14
lines changed

Z-Algorithm/README.markdown

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ This a simple description of the idea that is behind this algorithm. There are a
2828
Here is the code of the function that computes the Z-array:
2929
```swift
3030
func ZetaAlgorithm(ptrn: String) -> [Int]? {
31-
32-
let pattern = Array(ptrn.characters)
31+
let pattern = Array(ptrn)
3332
let patternLength: Int = pattern.count
3433

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

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

Z-Algorithm/ZAlgorithm.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
import Foundation
1010

1111
func ZetaAlgorithm(ptrn: String) -> [Int]? {
12-
13-
let pattern = Array(ptrn.characters)
12+
let pattern = Array(ptrn)
1413
let patternLength = pattern.count
1514

1615
guard patternLength > 0 else {

Z-Algorithm/ZetaAlgorithm.playground/Contents.swift

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
//: Playground - noun: a place where people can play
22

3-
// last checked with Xcode 9.0b4
4-
#if swift(>=4.0)
5-
print("Hello, Swift 4!")
6-
#endif
7-
83
func ZetaAlgorithm(ptrn: String) -> [Int]? {
9-
10-
let pattern = Array(ptrn.characters)
4+
let pattern = Array(ptrn)
115
let patternLength = pattern.count
126

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

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

7165
guard zeta != nil else {

Z-Algorithm/ZetaAlgorithm.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Foundation
1111
extension String {
1212

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

1717
guard zeta != nil else {

0 commit comments

Comments
 (0)