(t, p []rune)
| 14 | } |
| 15 | |
| 16 | func horspool(t, p []rune) (int, error) { |
| 17 | shiftMap := computeShiftMap(t, p) |
| 18 | pos := 0 |
| 19 | for pos <= len(t)-len(p) { |
| 20 | if isMatch(pos, t, p) { |
| 21 | return pos, nil |
| 22 | } |
| 23 | if pos+len(p) >= len(t) { |
| 24 | // because the remaining length of the input string |
| 25 | // is the same as the length of the pattern |
| 26 | // and it does not match the pattern |
| 27 | // it is impossible to find the pattern |
| 28 | break |
| 29 | } |
| 30 | |
| 31 | // because of the check above |
| 32 | // t[pos+len(p)] is defined |
| 33 | pos += shiftMap[t[pos+len(p)]] |
| 34 | } |
| 35 | |
| 36 | return -1, ErrNotFound |
| 37 | } |
| 38 | |
| 39 | // Checks if the array p matches the subarray of t starting at pos. |
| 40 | // Note that backward iteration. |
no test coverage detected