Skip to content

Commit 07732e8

Browse files
fix deprecated methods and return type
1 parent 3d8ad39 commit 07732e8

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

Boyer-Moore-Horspool/BoyerMooreHorspool.playground/Contents.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
http://www.drdobbs.com/database/faster-string-searches/184408171
1414
*/
1515
extension String {
16-
func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Index? {
16+
func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Int? {
1717
// Cache the length of the search pattern because we're going to
1818
// use it a few times and it's expensive to calculate.
19-
let patternLength = pattern.characters.count
20-
guard patternLength > 0, patternLength <= characters.count else { return nil }
19+
let patternLength = pattern.count
20+
guard patternLength > 0, patternLength <= self.count else { return nil }
2121

2222
// Make the skip table. This table determines how far we skip ahead
2323
// when a character from the pattern is found.
2424
var skipTable = [Character: Int]()
25-
for (i, c) in pattern.characters.enumerated() {
25+
for (i, c) in pattern.enumerated() {
2626
skipTable[c] = patternLength - i - 1
2727
}
2828

@@ -57,7 +57,7 @@ extension String {
5757
if c == lastChar {
5858

5959
// There is a possible match. Do a brute-force search backwards.
60-
if let k = backwards() { return k }
60+
if let k = backwards() { return k.encodedOffset }
6161

6262
if !usingHorspoolImprovement {
6363
// If no match, we can only safely skip one character ahead.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Boyer-Moore-Horspool/BoyerMooreHorspool.playground/timeline.xctimeline

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
version = "3.0">
44
<TimelineItems>
55
<LoggerValueHistoryTimelineItem
6-
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=75&amp;EndingColumnNumber=37&amp;EndingLineNumber=3&amp;StartingColumnNumber=9&amp;StartingLineNumber=3&amp;Timestamp=503226447.616217"
6+
documentLocation = "file:///Users/francisco_saldana/Documents/Nearsoft/Open%20source/swift-algorithm-club/Boyer-Moore-Horspool/BoyerMooreHorspool.playground#CharacterRangeLen=0&amp;CharacterRangeLoc=75&amp;EndingColumnNumber=21&amp;EndingLineNumber=2&amp;StartingColumnNumber=21&amp;StartingLineNumber=2&amp;Timestamp=563159867.556089"
77
selectedRepresentationIndex = "0"
88
shouldTrackSuperviewWidth = "NO">
99
</LoggerValueHistoryTimelineItem>
1010
<LoggerValueHistoryTimelineItem
11-
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=75&amp;EndingColumnNumber=26&amp;EndingLineNumber=3&amp;StartingColumnNumber=9&amp;StartingLineNumber=3&amp;Timestamp=503226447.61657"
11+
documentLocation = "file:///Users/francisco_saldana/Documents/Nearsoft/Open%20source/swift-algorithm-club/Boyer-Moore-Horspool/BoyerMooreHorspool.playground#CharacterRangeLen=0&amp;CharacterRangeLoc=75&amp;EndingColumnNumber=21&amp;EndingLineNumber=2&amp;StartingColumnNumber=21&amp;StartingLineNumber=2&amp;Timestamp=563159867.5563149"
1212
selectedRepresentationIndex = "0"
1313
shouldTrackSuperviewWidth = "NO">
1414
</LoggerValueHistoryTimelineItem>
1515
<LoggerValueHistoryTimelineItem
16-
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=75&amp;EndingColumnNumber=25&amp;EndingLineNumber=3&amp;StartingColumnNumber=9&amp;StartingLineNumber=3&amp;Timestamp=503226447.616725"
16+
documentLocation = "file:///Users/francisco_saldana/Documents/Nearsoft/Open%20source/swift-algorithm-club/Boyer-Moore-Horspool/BoyerMooreHorspool.playground#CharacterRangeLen=0&amp;CharacterRangeLoc=75&amp;EndingColumnNumber=21&amp;EndingLineNumber=2&amp;StartingColumnNumber=21&amp;StartingLineNumber=2&amp;Timestamp=563159867.556504"
1717
selectedRepresentationIndex = "0"
1818
shouldTrackSuperviewWidth = "NO">
1919
</LoggerValueHistoryTimelineItem>

Boyer-Moore-Horspool/BoyerMooreHorspool.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
http://www.drdobbs.com/database/faster-string-searches/184408171
77
*/
88
extension String {
9-
func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Index? {
9+
func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Int? {
1010
// Cache the length of the search pattern because we're going to
1111
// use it a few times and it's expensive to calculate.
12-
let patternLength = pattern.characters.count
13-
guard patternLength > 0, patternLength <= characters.count else { return nil }
12+
let patternLength = pattern.count
13+
guard patternLength > 0, patternLength <= self.count else { return nil }
1414

1515
// Make the skip table. This table determines how far we skip ahead
1616
// when a character from the pattern is found.
1717
var skipTable = [Character: Int]()
18-
for (i, c) in pattern.characters.enumerated() {
18+
for (i, c) in pattern.enumerated() {
1919
skipTable[c] = patternLength - i - 1
2020
}
2121

@@ -50,7 +50,7 @@ extension String {
5050
if c == lastChar {
5151

5252
// There is a possible match. Do a brute-force search backwards.
53-
if let k = backwards() { return k }
53+
if let k = backwards() { return k.encodedOffset }
5454

5555
if !usingHorspoolImprovement {
5656
// If no match, we can only safely skip one character ahead.

0 commit comments

Comments
 (0)