[go] internal/bytealg: unexport {Last,}IndexRabinKarp helpers

2 views
Skip to first unread message

Tobias Klauser (Gerrit)

unread,
Feb 4, 2026, 10:30:22 AM (3 days ago) Feb 4
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Tobias Klauser has uploaded the change for review

Commit message

internal/bytealg: unexport {Last,}IndexRabinKarp helpers

After CL 538737 these no longer need to be exported. They are only
used in internal/bytealg and can be unexported.
Change-Id: Idd405f397c7ec9f96425d2b7e0e74de61daa7a6e

Change diff

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) {

Change information

Files:
  • M src/internal/bytealg/bytealg.go
Change size: S
Delta: 1 file changed, 16 insertions(+), 16 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Idd405f397c7ec9f96425d2b7e0e74de61daa7a6e
Gerrit-Change-Number: 741920
Gerrit-PatchSet: 1
Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Keith Randall (Gerrit)

unread,
Feb 6, 2026, 6:13:17 PM (8 hours ago) Feb 6
to Tobias Klauser, goph...@pubsubhelper.golang.org, Keith Randall, Go LUCI, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Tobias Klauser

Keith Randall voted Code-Review+2

Code-Review+2
Open in Gerrit

Related details

Attention is currently required from:
  • Tobias Klauser
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Idd405f397c7ec9f96425d2b7e0e74de61daa7a6e
Gerrit-Change-Number: 741920
Gerrit-PatchSet: 1
Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-Attention: Tobias Klauser <tobias....@gmail.com>
Gerrit-Comment-Date: Fri, 06 Feb 2026 23:13:12 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Keith Randall (Gerrit)

unread,
Feb 6, 2026, 6:13:25 PM (8 hours ago) Feb 6
to Tobias Klauser, goph...@pubsubhelper.golang.org, Keith Randall, Go LUCI, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Tobias Klauser

Keith Randall voted Code-Review+1

Code-Review+1
Open in Gerrit

Related details

Attention is currently required from:
  • Tobias Klauser
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Idd405f397c7ec9f96425d2b7e0e74de61daa7a6e
Gerrit-Change-Number: 741920
Gerrit-PatchSet: 1
Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Reviewer: Keith Randall <k...@google.com>
Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-Attention: Tobias Klauser <tobias....@gmail.com>
Gerrit-Comment-Date: Fri, 06 Feb 2026 23:13:20 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Michael Pratt (Gerrit)

unread,
Feb 6, 2026, 6:30:36 PM (8 hours ago) Feb 6
to Tobias Klauser, goph...@pubsubhelper.golang.org, Michael Pratt, Keith Randall, Keith Randall, Go LUCI, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Tobias Klauser

Michael Pratt voted Code-Review+1

Code-Review+1
Open in Gerrit

Related details

Attention is currently required from:
  • Tobias Klauser
Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Idd405f397c7ec9f96425d2b7e0e74de61daa7a6e
    Gerrit-Change-Number: 741920
    Gerrit-PatchSet: 1
    Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Keith Randall <k...@google.com>
    Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
    Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Comment-Date: Fri, 06 Feb 2026 23:30:33 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    open
    diffy

    Gopher Robot (Gerrit)

    unread,
    Feb 6, 2026, 6:30:53 PM (8 hours ago) Feb 6
    to Tobias Klauser, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Michael Pratt, Keith Randall, Keith Randall, Go LUCI, golang-co...@googlegroups.com

    Gopher Robot submitted the change

    Change information

    Commit message:
    internal/bytealg: unexport {Last,}IndexRabinKarp helpers

    After CL 538737 these no longer need to be exported. They are only
    used in internal/bytealg and can be unexported.
    Change-Id: Idd405f397c7ec9f96425d2b7e0e74de61daa7a6e
    Reviewed-by: Keith Randall <k...@golang.org>
    Reviewed-by: Michael Pratt <mpr...@google.com>
    Auto-Submit: Tobias Klauser <tobias....@gmail.com>
    Reviewed-by: Keith Randall <k...@google.com>
    Files:
    • M src/internal/bytealg/bytealg.go
    Change size: S
    Delta: 1 file changed, 16 insertions(+), 16 deletions(-)
    Branch: refs/heads/master
    Submit Requirements:
    • requirement satisfiedCode-Review: +1 by Michael Pratt, +2 by Keith Randall, +1 by Keith Randall
    • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
    Open in Gerrit
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: merged
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Idd405f397c7ec9f96425d2b7e0e74de61daa7a6e
    Gerrit-Change-Number: 741920
    Gerrit-PatchSet: 2
    Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    open
    diffy
    satisfied_requirement
    Reply all
    Reply to author
    Forward
    0 new messages