Skip to content

Commit

Permalink
fix deprecated methods and return type
Browse files Browse the repository at this point in the history
  • Loading branch information
pakosaldanaort committed Nov 6, 2018
1 parent 3d8ad39 commit 07732e8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
http://www.drdobbs.com/database/faster-string-searches/184408171
*/
extension String {
func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Index? {
func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Int? {
// Cache the length of the search pattern because we're going to
// use it a few times and it's expensive to calculate.
let patternLength = pattern.characters.count
guard patternLength > 0, patternLength <= characters.count else { return nil }
let patternLength = pattern.count
guard patternLength > 0, patternLength <= self.count else { return nil }

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

Expand Down Expand Up @@ -57,7 +57,7 @@ extension String {
if c == lastChar {

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

if !usingHorspoolImprovement {
// If no match, we can only safely skip one character ahead.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
version = "3.0">
<TimelineItems>
<LoggerValueHistoryTimelineItem
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=75&amp;EndingColumnNumber=37&amp;EndingLineNumber=3&amp;StartingColumnNumber=9&amp;StartingLineNumber=3&amp;Timestamp=503226447.616217"
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"
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=75&amp;EndingColumnNumber=26&amp;EndingLineNumber=3&amp;StartingColumnNumber=9&amp;StartingLineNumber=3&amp;Timestamp=503226447.61657"
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"
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=75&amp;EndingColumnNumber=25&amp;EndingLineNumber=3&amp;StartingColumnNumber=9&amp;StartingLineNumber=3&amp;Timestamp=503226447.616725"
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"
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
Expand Down
10 changes: 5 additions & 5 deletions Boyer-Moore-Horspool/BoyerMooreHorspool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
http://www.drdobbs.com/database/faster-string-searches/184408171
*/
extension String {
func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Index? {
func index(of pattern: String, usingHorspoolImprovement: Bool = false) -> Int? {
// Cache the length of the search pattern because we're going to
// use it a few times and it's expensive to calculate.
let patternLength = pattern.characters.count
guard patternLength > 0, patternLength <= characters.count else { return nil }
let patternLength = pattern.count
guard patternLength > 0, patternLength <= self.count else { return nil }

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

Expand Down Expand Up @@ -50,7 +50,7 @@ extension String {
if c == lastChar {

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

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

0 comments on commit 07732e8

Please sign in to comment.