diff --git a/src/internal/bytealg/bytealg.go b/src/internal/bytealg/bytealg.go
index 319ea54..57a1e4d 100644
--- a/src/internal/bytealg/bytealg.go
+++ b/src/internal/bytealg/bytealg.go
@@ -29,17 +29,17 @@
// If MaxLen is not 0, make sure MaxLen >= 4.
var MaxLen int
-// PrimeRK is the prime base used in Rabin-Karp algorithm.
-const PrimeRK = 16777619
+// primeRK is the prime base used in Rabin-Karp algorithm.
+const primeRK = 16777619
-// HashStr returns the hash and the appropriate multiplicative
+// hashStr returns the hash and the appropriate multiplicative
// factor for use in Rabin-Karp algorithm.
-func HashStr[T string | []byte](sep T) (uint32, uint32) {
+func hashStr[T string | []byte](sep T) (uint32, uint32) {
hash := uint32(0)
for i := 0; i < len(sep); i++ {
- hash = hash*PrimeRK + uint32(sep[i])
+ hash = hash*primeRK + uint32(sep[i])
}
- var pow, sq uint32 = 1, PrimeRK
+ var pow, sq uint32 = 1, primeRK
for i := len(sep); i > 0; i >>= 1 {
if i&1 != 0 {
pow *= sq
@@ -49,14 +49,14 @@
return hash, pow
}
-// HashStrRev returns the hash of the reverse of sep and the
+// hashStrRev returns the hash of the reverse of sep and the
// appropriate multiplicative factor for use in Rabin-Karp algorithm.
-func HashStrRev[T string | []byte](sep T) (uint32, uint32) {
+func hashStrRev[T string | []byte](sep T) (uint32, uint32) {
hash := uint32(0)
for i := len(sep) - 1; i >= 0; i-- {
- hash = hash*PrimeRK + uint32(sep[i])
+ hash = hash*primeRK + uint32(sep[i])
}
- var pow, sq uint32 = 1, PrimeRK
+ var pow, sq uint32 = 1, primeRK
for i := len(sep); i > 0; i >>= 1 {
if i&1 != 0 {
pow *= sq
@@ -70,17 +70,17 @@
// first occurrence of sep in s, or -1 if not present.
func IndexRabinKarp[T string | []byte](s, sep T) int {
// Rabin-Karp search
- hashss, pow := HashStr(sep)
+ hashss, pow := hashStr(sep)
n := len(sep)
var h uint32
for i := 0; i < n; i++ {
- h = h*PrimeRK + uint32(s[i])
+ h = h*primeRK + uint32(s[i])
}
if h == hashss && string(s[:n]) == string(sep) {
return 0
}
for i := n; i < len(s); {
- h *= PrimeRK
+ h *= primeRK
h += uint32(s[i])
h -= pow * uint32(s[i-n])
i++
@@ -95,18 +95,18 @@
// occurrence of sep in s, or -1 if not present.
func LastIndexRabinKarp[T string | []byte](s, sep T) int {
// Rabin-Karp search from the end of the string
- hashss, pow := HashStrRev(sep)
+ hashss, pow := hashStrRev(sep)
n := len(sep)
last := len(s) - n
var h uint32
for i := len(s) - 1; i >= last; i-- {
- h = h*PrimeRK + uint32(s[i])
+ h = h*primeRK + uint32(s[i])
}
if h == hashss && string(s[last:]) == string(sep) {
return last
}
for i := last - 1; i >= 0; i-- {
- h *= PrimeRK
+ h *= primeRK
h += uint32(s[i])
h -= pow * uint32(s[i+n])
if h == hashss && string(s[i:i+n]) == string(sep) {