github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/bytealg/bytealg.go (about) 1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package bytealg 6 7 // MaxLen is the maximum length of the string to be searched for (argument b) in Index. 8 // If MaxLen is not 0, make sure MaxLen >= 4. 9 var MaxLen int 10 11 // PrimeRK is the prime base used in Rabin-Karp algorithm. 12 const PrimeRK = 16777619 13 14 // HashStr returns the hash and the appropriate multiplicative 15 // factor for use in Rabin-Karp algorithm. 16 func HashStr[T string | []byte](sep T) (uint32, uint32) 17 18 // HashStrRev returns the hash of the reverse of sep and the 19 // appropriate multiplicative factor for use in Rabin-Karp algorithm. 20 func HashStrRev[T string | []byte](sep T) (uint32, uint32) 21 22 // IndexRabinKarp uses the Rabin-Karp search algorithm to return the index of the 23 // first occurrence of sep in s, or -1 if not present. 24 func IndexRabinKarp[T string | []byte](s, sep T) int 25 26 // LastIndexRabinKarp uses the Rabin-Karp search algorithm to return the last index of the 27 // occurrence of sep in s, or -1 if not present. 28 func LastIndexRabinKarp[T string | []byte](s, sep T) int 29 30 // MakeNoZero makes a slice of length n and capacity of at least n Bytes 31 // without zeroing the bytes (including the bytes between len and cap). 32 // It is the caller's responsibility to ensure uninitialized bytes 33 // do not leak to the end user. 34 func MakeNoZero(n int) []byte