Standard library / hash/maphash

hash/maphash.Hash.Sum()

Append the eight-byte digest to the prefix without changing the hash state. The installed implementation uses little-endian digest bytes; prefer Sum64 for numeric results. This is not a cryptographic authentication primitive. Expected stdout: 'P 9 true\n'.

Formal Syntax & Structure

go syntaxgo
func (h *Hash) Sum(b []byte) []byte

Parameters & Attributes

NameTypeDescription
b[]byteExisting prefix to which the digest is appended.

Return Value

[]byte

Prefix followed by current digest.

Working Example

Example Snippetgo
package main
import (  "encoding/binary"  "fmt"  "hash/maphash")
func main() {  var h maphash.Hash  h.WriteString("Go")  b := h.Sum([]byte("P"))  fmt.Println(string(b[:1]), len(b), binary.LittleEndian.Uint64(b[1:]) == h.Sum64())}
Go Reference