bytealg

package standard library
go1.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const MaxBruteForce = 64
View Source
const PrimeRK = 16777619

PrimeRK is the prime base used in Rabin-Karp algorithm.

Variables ΒΆ

View Source
var MaxLen int

MaxLen is the maximum length of the string to be searched for (argument b) in Index. If MaxLen is not 0, make sure MaxLen >= 4.

Functions ΒΆ

func Compare ΒΆ

func Compare(a, b []byte) int

func CompareString ΒΆ added in go1.23.0

func CompareString(a, b string) int

func Count ΒΆ

func Count(b []byte, c byte) int

func CountString ΒΆ

func CountString(s string, c byte) int

func Cutover ΒΆ

func Cutover(n int) int

Cutover reports the number of failures of IndexByte we should tolerate before switching over to Index. n is the number of bytes processed so far. See the bytes.Index implementation for details.

func Equal ΒΆ

func Equal(a, b []byte) bool

Equal reports whether a and b are the same length and contain the same bytes. A nil argument is equivalent to an empty slice.

Equal is equivalent to bytes.Equal. It is provided here for convenience, because some packages cannot depend on bytes.

func HashStr ΒΆ added in go1.15

func HashStr[T string | []byte](sep T) (uint32, uint32)

HashStr returns the hash and the appropriate multiplicative factor for use in Rabin-Karp algorithm.

func HashStrRev ΒΆ added in go1.15

func HashStrRev[T string | []byte](sep T) (uint32, uint32)

HashStrRev returns the hash of the reverse of sep and the appropriate multiplicative factor for use in Rabin-Karp algorithm.

func Index ΒΆ

func Index(a, b []byte) int

Index returns the index of the first instance of b in a, or -1 if b is not present in a. Requires 2 <= len(b) <= MaxLen.

func IndexByte ΒΆ

func IndexByte(b []byte, c byte) int

func IndexByteString ΒΆ

func IndexByteString(s string, c byte) int

func IndexRabinKarp ΒΆ added in go1.15

func IndexRabinKarp[T string | []byte](s, sep T) int

IndexRabinKarp uses the Rabin-Karp search algorithm to return the index of the first occurrence of sep in s, or -1 if not present.

func IndexString ΒΆ

func IndexString(a, b string) int

IndexString returns the index of the first instance of b in a, or -1 if b is not present in a. Requires 2 <= len(b) <= MaxLen.

func LastIndexByte ΒΆ added in go1.22.0

func LastIndexByte(s []byte, c byte) int

func LastIndexByteString ΒΆ added in go1.22.0

func LastIndexByteString(s string, c byte) int

func LastIndexRabinKarp ΒΆ added in go1.22.0

func LastIndexRabinKarp[T string | []byte](s, sep T) int

LastIndexRabinKarp uses the Rabin-Karp search algorithm to return the last index of the occurrence of sep in s, or -1 if not present.

func MakeNoZero ΒΆ added in go1.21.0

func MakeNoZero(n int) []byte

MakeNoZero makes a slice of length n and capacity of at least n Bytes without zeroing the bytes (including the bytes between len and cap). It is the caller's responsibility to ensure uninitialized bytes do not leak to the end user.

Types ΒΆ

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL