File tree 4 files changed +6
-14
lines changed
4 files changed +6
-14
lines changed Original file line number Diff line number Diff line change @@ -28,8 +28,7 @@ This a simple description of the idea that is behind this algorithm. There are a
28
28
Here is the code of the function that computes the Z-array:
29
29
``` swift
30
30
func ZetaAlgorithm (ptrn : String ) -> [Int ]? {
31
-
32
- let pattern = Array (ptrn.characters )
31
+ let pattern = Array (ptrn)
33
32
let patternLength: Int = pattern.count
34
33
35
34
guard patternLength > 0 else {
@@ -131,7 +130,7 @@ The Z-Algorithm discussed above leads to the simplest linear-time string matchin
131
130
extension String {
132
131
133
132
func indexesOf (pattern : String ) -> [Int ]? {
134
- let patternLength: Int = pattern.characters . count
133
+ let patternLength: Int = pattern.count
135
134
/* Let's calculate the Z-Algorithm on the concatenation of pattern and text */
136
135
let zeta = ZetaAlgorithm (ptrn : pattern + " 💲" + self )
137
136
Original file line number Diff line number Diff line change 9
9
import Foundation
10
10
11
11
func ZetaAlgorithm( ptrn: String ) -> [ Int ] ? {
12
-
13
- let pattern = Array ( ptrn. characters)
12
+ let pattern = Array ( ptrn)
14
13
let patternLength = pattern. count
15
14
16
15
guard patternLength > 0 else {
Original file line number Diff line number Diff line change 1
1
//: Playground - noun: a place where people can play
2
2
3
- // last checked with Xcode 9.0b4
4
- #if swift(>=4.0)
5
- print ( " Hello, Swift 4! " )
6
- #endif
7
-
8
3
func ZetaAlgorithm( ptrn: String ) -> [ Int ] ? {
9
-
10
- let pattern = Array ( ptrn. characters)
4
+ let pattern = Array ( ptrn)
11
5
let patternLength = pattern. count
12
6
13
7
guard patternLength > 0 else {
@@ -65,7 +59,7 @@ func ZetaAlgorithm(ptrn: String) -> [Int]? {
65
59
extension String {
66
60
67
61
func indexesOf( pattern: String ) -> [ Int ] ? {
68
- let patternLength = pattern. characters . count
62
+ let patternLength = pattern. count
69
63
let zeta = ZetaAlgorithm ( ptrn: pattern + " 💲 " + self )
70
64
71
65
guard zeta != nil else {
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import Foundation
11
11
extension String {
12
12
13
13
func indexesOf( pattern: String ) -> [ Int ] ? {
14
- let patternLength = pattern. characters . count
14
+ let patternLength = pattern. count
15
15
let zeta = ZetaAlgorithm ( ptrn: pattern + " 💲 " + self )
16
16
17
17
guard zeta != nil else {
You can’t perform that action at this time.
0 commit comments