Documentation
¶
Index ¶
- func DefaultHasher(key, member []byte) uint64
- type Builder
- func (b *Builder) Add(e ...Entry) *Builder
- func (b *Builder) AddMember(m interface{}, v []byte) *Builder
- func (b *Builder) AddStrings(ms ...string) *Builder
- func (b *Builder) Hash32(hf func() hash.Hash32) *Builder
- func (b *Builder) Hash64(hf func() hash.Hash64) *Builder
- func (b *Builder) Hasher(h Hasher) *Builder
- func (b *Builder) New() *Hash
- type Entry
- type Hash
- type Hasher
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultHasher ¶
DefaultHasher is the default hash implementation, which uses a FNV-1 64a hasher under the covers.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is a mutable, fluent builder for Hash instances. Builders are not safe for concurrent reads and writes. The zero value for this struct is a valid instance.
func (*Builder) AddStrings ¶
AddStrings adds several string members, where each member's hash value is simply the byte slice representation of the string.
type Entry ¶
type Entry struct { // Member is the object returned by the rendezvous hash for a given key Member interface{} // Value is the hash value of the member Value []byte }
Entry is a tuple containing the member object together with its hash value
type Hash ¶
type Hash struct {
// contains filtered or unexported fields
}
Hash implements a rendezvous hash over a set of members. A Hash instance is safe for concurrent reads and writes. It is immutable once created by a Builder.
Hash values are created by concatenating key bytes and member bytes, then computing the hash based on that single byte slice.
Example ¶
h := new(Builder). Hash32(fnv.New32a). AddStrings("foo.com", "bar.net").New() fmt.Println(h.GetString("mac:112233445566"))
Output: bar.net
func EmptyHash ¶
func EmptyHash() *Hash
EmptyHash returns the canonicalized empty Hash instance. This is used mainly by the builder when no entries have been added.
type Hasher ¶
Hasher is the strategy for hashing an object and a member together
func NewHasher32 ¶
NewHasher32 uses a 32-bit hash constructor, such as fnv.New32a, as the basis for the returned Hasher implementation
func NewHasher64 ¶
NewHasher64 uses a 64-bit hash constructor, such as fnv.New64a, as the basis for the returned Hasher implementation