diff options
Diffstat (limited to 'src/bytes/bytes.go')
| -rw-r--r-- | src/bytes/bytes.go | 20 |
1 files changed, 1 insertions, 19 deletions
diff --git a/src/bytes/bytes.go b/src/bytes/bytes.go index c84accd8f5..0679b43a20 100644 --- a/src/bytes/bytes.go +++ b/src/bytes/bytes.go @@ -121,25 +121,7 @@ func LastIndex(s, sep []byte) int { case n > len(s): return -1 } - // Rabin-Karp search from the end of the string - hashss, pow := bytealg.HashStrRev(sep) - last := len(s) - n - var h uint32 - for i := len(s) - 1; i >= last; i-- { - h = h*bytealg.PrimeRK + uint32(s[i]) - } - if h == hashss && Equal(s[last:], sep) { - return last - } - for i := last - 1; i >= 0; i-- { - h *= bytealg.PrimeRK - h += uint32(s[i]) - h -= pow * uint32(s[i+n]) - if h == hashss && Equal(s[i:i+n], sep) { - return i - } - } - return -1 + return bytealg.LastIndexRabinKarp(s, sep) } // LastIndexByte returns the index of the last instance of c in s, or -1 if c is not present in s. |
