rendezvous

package module
v0.0.0-...-ceda35a Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultHasher

func DefaultHasher(key, member []byte) uint64

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) Add

func (b *Builder) Add(e ...Entry) *Builder

Add appends entries to the final Hash

func (*Builder) AddMember

func (b *Builder) AddMember(m interface{}, v []byte) *Builder

AddMember appends a single member together with its hash value

func (*Builder) AddStrings

func (b *Builder) AddStrings(ms ...string) *Builder

AddStrings adds several string members, where each member's hash value is simply the byte slice representation of the string.

func (*Builder) Hash32

func (b *Builder) Hash32(hf func() hash.Hash32) *Builder

Hash32 uses a 32-bit hashing constructor as the hash algorithm

func (*Builder) Hash64

func (b *Builder) Hash64(hf func() hash.Hash64) *Builder

Hash64 uses a 64-bit hashing constructor as the hash algorithm

func (*Builder) Hasher

func (b *Builder) Hasher(h Hasher) *Builder

Hasher sets the Hasher strategy for the next Hash created by this builder. By default, DefaultHasher is used.

func (*Builder) New

func (b *Builder) New() *Hash

New creates a Hash using this Builder's current configuration. This builder is reset prior to returning.

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.

func (*Hash) Get

func (h *Hash) Get(key []byte) interface{}

Get returns the result of a rendezvous hash given an arbitrary key

func (*Hash) GetString

func (h *Hash) GetString(key string) interface{}

GetString returns the result of a rendezvous hash using a string key

func (*Hash) Len

func (h *Hash) Len() int

Len returns the number of entries in the rendezvous hash table. If this method returns 0, all methods that return members will return nil.

type Hasher

type Hasher func(key, member []byte) uint64

Hasher is the strategy for hashing an object and a member together

func NewHasher32

func NewHasher32(hf func() hash.Hash32) Hasher

NewHasher32 uses a 32-bit hash constructor, such as fnv.New32a, as the basis for the returned Hasher implementation

func NewHasher64

func NewHasher64(hf func() hash.Hash64) Hasher

NewHasher64 uses a 64-bit hash constructor, such as fnv.New64a, as the basis for the returned Hasher implementation

Jump to

Keyboard shortcuts

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