Documentation
¶
Overview ¶
Package anyunique provides canonicalization of values under a caller-defined equivalence relation.
A Set holds a set of unique values of a specific type T. Calling Set.Make with two values that are equivalent according to the provided Hasher returns Handle values that are identical. Handle is a lightweight wrapper around the canonical value; use Handle.Value to obtain the underlying T.
The zero Handle represents the zero value of T. Make returns the zero Handle when called with the zero value of T: it will never try to hash the zero value.
[Set.WriteHash] writes a short representation of a canonicalized value to a maphash.Hash. It is useful when hashing structures that themselves contain canonicalized values, avoiding re-hashing the full value graph.
Values in a set are amenable to garbage collection: the set does not necesarily always grow in size.
NOTE this package assumes that T values are treated as immutable. That is, after calling Set.Make a value must not change.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handle ¶
type Handle[T any] struct { // contains filtered or unexported fields }
Handle represents a unique value of type T. If two values of type Handle[T] originating from the same Set compare equal, they are guaranteed to be equal according to the equality criteria that the set was created with.
type Hasher ¶
type Hasher[T any] interface { comparable Hash(*maphash.Hash, T) Equal(x, y T) bool }
A Hasher defines a hash function and an equivalence relation over values of type T.
Hash must write a hash of its argument to the provided *maphash.Hash, and Equal must report whether two values are equivalent. Hash and Equal must be consistent: if Equal(x, y) is true then Hash must produce the same output for x and y.
See https://go-review.googlesource.com/c/go/+/657296/11/src/hash/maphash/hasher.go