Skip to content

Commit f4dc41f

Browse files
author
Kevin Taniguchi
committed
began convert to swift3
1 parent e22b376 commit f4dc41f

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

Boyer-Moore/BoyerMoore.playground/Contents.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ extension String {
77
assert(patternLength <= self.characters.count)
88

99
var skipTable = [Character: Int]()
10-
for (i, c) in pattern.characters.enumerate() {
10+
for (i, c) in pattern.characters.enumerated() {
1111
skipTable[c] = patternLength - i - 1
1212
}
1313

14-
let p = pattern.endIndex.predecessor()
14+
let p = pattern.index(before: endIndex)
1515
let lastChar = pattern[p]
16-
var i = self.startIndex.advancedBy(patternLength - 1)
16+
var i = self.index(startIndex, offsetBy: patternLength - 1)
1717

1818
func backwards() -> String.Index? {
1919
var q = p
2020
var j = i
2121
while q > pattern.startIndex {
22-
j = j.predecessor()
23-
q = q.predecessor()
22+
j = index(before: j)
23+
q = index(before: q)
2424
if self[j] != pattern[q] { return nil }
2525
}
2626
return j
@@ -30,9 +30,9 @@ extension String {
3030
let c = self[i]
3131
if c == lastChar {
3232
if let k = backwards() { return k }
33-
i = i.successor()
33+
i = index(after: i)
3434
} else {
35-
i = i.advancedBy(skipTable[c] ?? patternLength)
35+
i = index(i, offsetBy: skipTable[c] ?? patternLength)
3636
}
3737
}
3838
return nil
@@ -44,7 +44,7 @@ extension String {
4444
// A few simple tests
4545

4646
let s = "Hello, World"
47-
s.indexOf("World") // 7
47+
s.indexOf(pattern: "World") // 7
4848

4949
let animals = "🐶🐔🐷🐮🐱"
50-
animals.indexOf("🐮") // 6
50+
animals.indexOf(pattern: "🐮") // 6

Boyer-Moore/BoyerMoore.playground/timeline.xctimeline

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)