hashutils

package
v0.31.6 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package hashutils provides utilities for hashing objects in a stable way. The hash returned should be considered stable when a hasher is provided. If a hasher is not provided, the default hasher is used, which is currently xxhash, but may change resulting in different hashes. It is OK to use the default hasher for temporary hashes, but for long-term storage, a specific hasher should be provided. The hash returned is a 64-bit non-cryptographic hash.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashAny

func HashAny(hasher Hasher, value any) uint64

HashAny hashes an arbitrary Go value (the result of json.Unmarshal) in a canonical way using the provided hasher. It returns a 64-bit non-cryptographic hash.

func HashJSON

func HashJSON(hasher Hasher, input []byte) (uint64, error)

HashJSON takes a blob of JSON, unmarshals it, and returns a 64-bit hash using the provided hasher. If there's an error unmarshaling, it returns 0 and the error.

func HashStrings added in v0.15.0

func HashStrings(hasher Hasher, values ...string) uint64

Types

type Hasher

type Hasher interface {
	Write(p []byte) (n int, err error)
	Sum64() uint64
}

Hasher is an interface that wraps a Sum64 method. Any hash implementation that implements Sum64 can be used with HashAny.

Jump to

Keyboard shortcuts

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