Documentation
¶
Index ¶
- Constants
- func HashStrings(ins ...string) digest.Digest
- type Hasher
- func (h *Hasher) Close()
- func (h *Hasher) DigestAndClose() string
- func (h *Hasher) WithByte(b byte) *Hasher
- func (h *Hasher) WithBytes(bs ...byte) *Hasher
- func (h *Hasher) WithDelim() *Hasher
- func (h *Hasher) WithFloat64(f float64) *Hasher
- func (h *Hasher) WithInt32(i int32) *Hasher
- func (h *Hasher) WithInt64(i int64) *Hasher
- func (h *Hasher) WithString(s string) *Hasher
- func (h *Hasher) WithUint64(i uint64) *Hasher
Constants ¶
const (
XXH3 digest.Algorithm = "xxh3"
)
Variables ¶
This section is empty.
Functions ¶
func HashStrings ¶
HashStrings returns the xxh3 digest of the concatenation of the input strings, separated by null bytes to avoid collisions. It's more convenient than NewHasher when all inputs are already strings.
Types ¶
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Hasher enables efficient hashing of mixed inputs of various types. It's intended for hot codepaths where minimizing allocations and overhead is important.
Inputs are separated by null bytes to avoid collisions (e.g. "ab" + "c" vs "a" + "bc").
Small inputs are batched in a buffer that is written to the streaming xxh3 hasher when it fills up or when the digest is computed; large inputs are written to the xxh3 hasher directly. Since xxh3 streaming yields the same hash for the same byte sequence however it's split across writes, the digest only depends on the sequence of inputs.
NOTE: all the With* methods are mutating Hasher, so it can't "branch" off to compute different hashes. It also is not safe to use after Close or DigestAndClose have been called.