"std:hash"Provides non-cryptographic hash functions. Implements FNV-1a (32-bit and 64-bit) and CRC32 (IEEE polynomial). All functions are pure Saurus with no external dependencies.
View source on Codeberg →type Hash32 struct {
state uint32
}
Hash32 holds the internal state for a 32-bit hash computation.
type Hash64 struct {
state uint64
}
Hash64 holds the internal state for a 64-bit hash computation.
func NewFNV32a() Hash32
Returns a new Hash32 initialized with the FNV-1a 32-bit offset basis.
func WriteFNV32a(h *Hash32, data []byte)
Feeds data into the FNV-1a 32-bit hash state. Can be called multiple times to hash data incrementally.
func SumFNV32a(h *Hash32) uint32
Returns the current FNV-1a 32-bit hash value. Does not reset the state.
func ResetFNV32a(h *Hash32)
Resets the hash state to the FNV-1a 32-bit offset basis, allowing reuse without allocation.
func NewFNV64a() Hash64
Returns a new Hash64 initialized with the FNV-1a 64-bit offset basis.
func WriteFNV64a(h *Hash64, data []byte)
Feeds data into the FNV-1a 64-bit hash state. Can be called multiple times to hash data incrementally.
func SumFNV64a(h *Hash64) uint64
Returns the current FNV-1a 64-bit hash value. Does not reset the state.
func ResetFNV64a(h *Hash64)
Resets the hash state to the FNV-1a 64-bit offset basis, allowing reuse without allocation.
func NewCRC32() Hash32
Returns a new Hash32 initialized for CRC32 computation using the IEEE polynomial.
func WriteCRC32(h *Hash32, data []byte)
Feeds data into the CRC32 hash state. Can be called multiple times to hash data incrementally.
func SumCRC32(h *Hash32) uint32
Returns the current CRC32 hash value. Does not reset the state.
func ResetCRC32(h *Hash32)
Resets the CRC32 hash state, allowing reuse without allocation.
func FNV32a(data []byte) uint32
Computes the FNV-1a 32-bit hash of a byte slice in a single call.
func FNV64a(data []byte) uint64
Computes the FNV-1a 64-bit hash of a byte slice in a single call.
func CRC32(data []byte) uint32
Computes the CRC32 hash (IEEE polynomial) of a byte slice in a single call.
func FNV32aString(s string) uint32
Computes the FNV-1a 32-bit hash of a string in a single call.
func FNV64aString(s string) uint64
Computes the FNV-1a 64-bit hash of a string in a single call.
func CRC32String(s string) uint32
Computes the CRC32 hash (IEEE polynomial) of a string in a single call.