type Hasher struct {
// contains filtered or unexported fields
} Create one with NewHasher; the zero value is not ready to use.
A fast 64-bit additive checksum and a seeded 64-bit non-cryptographic hash:
func Bytesum(str string) uint64
func Hash(str string, seed uint64) uint64sum := sz.Bytesum("hello")
h := sz.Hash("hello", 42)For incremental hashing, Hasher implements hash.Hash64 and io.Writer:
func NewHasher(seed uint64) *Hasher
func (h *Hasher) Write(p []byte) (n int, err error)
func (h *Hasher) Sum(b []byte) []byte
func (h *Hasher) Sum64() uint64
func (h *Hasher) Digest() uint64
func (h *Hasher) Reset()
func (h *Hasher) Size() int
func (h *Hasher) BlockSize() intSum64 and its alias Digest return the current digest without consuming the state.
Create a Hasher with NewHasher(seed); its zero value is not ready to use.
h := sz.NewHasher(0)
h.Write([]byte("hello "))
h.Write([]byte("world"))
digest := h.Sum64()A cryptographic SHA-256 is available both as a one-shot and as a streaming hasher implementing hash.Hash and io.Writer:
func HashSha256(data []byte) [32]byte
func NewSha256() *Sha256
func (h *Sha256) Write(p []byte) (n int, err error)
func (h *Sha256) Sum(b []byte) []byte
func (h *Sha256) Digest() [32]byte
func (h *Sha256) Hexdigest() string
func (h *Sha256) Reset()
func (h *Sha256) Size() int
func (h *Sha256) BlockSize() intDigest returns the raw 32-byte hash and Hexdigest returns its lowercase hex string, both without consuming the state.
Create a Sha256 with NewSha256(); its zero value is not ready to use.
sum := sz.HashSha256([]byte("hello"))
h := sz.NewSha256()
h.Write([]byte("hello"))
fmt.Println(h.Hexdigest())HasherHasher is a streaming 64-bit non-cryptographic hasher that implements hash.Hash64 and io.Writer.7type Hasher struct {
// contains filtered or unexported fields
} Create one with NewHasher; the zero value is not ready to use.
NewHasherNewHasher creates a new streaming hasher with the given seed.func NewHasher(seed uint64) *Hasher Block*BlockSize× 2BlockSize returns the hash's underlying block size.*× 2Digest returns the current 64-bit hash without consuming the state.func (h *Hasher) Digest() uint64 | Symbol |
|---|
Digest |
Sum64 |
This is an alias for Hasher.Sum64.
Implements hash.Hash64.
*Reset× 2Reset resets the hasher to its initial state.*Size× 2Size returns the number of bytes Sum will return.*Sum× 2Sum appends the current hash to b and returns the resulting slice.func (h *Hasher) Sum(b []byte) []byte It does not change the underlying hash state. Implements hash.Hash.
WriteWrite adds data to the streaming hasher.Sha256Sha256 is a streaming SHA-256 hasher that implements hash.Hash and io.Writer.4type Sha256 struct {
// contains filtered or unexported fields
} Create one with NewSha256; the zero value is not ready to use.
NewSha256NewSha256 creates a new streaming SHA-256 hasher.func NewSha256() *Sha256 DigestDigest returns the current SHA-256 hash as a 32-byte array without consuming the state.func (h *Sha256) Digest() [32]byte This is a convenience method in addition to the standard hash.Hash interface.
HexdigestHexdigest returns the current SHA-256 hash as a lowercase hexadecimal string.func (h *Sha256) Hexdigest() string This is a convenience wrapper over Sha256.Digest.
WriteWrite adds data to the streaming SHA-256 hasher.BytesumBytesum computes a simple 64-bit checksum by summing bytes.func Bytesum(str string) uint64 HashHash computes a 64-bit non-cryptographic hash with a seed.func Hash(str string, seed uint64) uint64 HashSha256HashSha256 computes the SHA-256 cryptographic hash of the input data.func HashSha256(data []byte) [32]byte