hashring

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HashFunc

type HashFunc func([]byte) HashKey

type HashKey

type HashKey interface {
	Less(other HashKey) bool
}

func NewInt64PairHashKey

func NewInt64PairHashKey(bytes []byte) (HashKey, error)

type HashKeyOrder

type HashKeyOrder []HashKey

func (HashKeyOrder) Len

func (h HashKeyOrder) Len() int

func (HashKeyOrder) Less

func (h HashKeyOrder) Less(i, j int) bool

func (HashKeyOrder) Swap

func (h HashKeyOrder) Swap(i, j int)

type HashRing

type HashRing struct {
	// contains filtered or unexported fields
}

func New

func New(nodes []string) *HashRing

func NewWithHash

func NewWithHash(
	nodes []string,
	hashKey HashFunc,
) *HashRing

func NewWithHashAndWeights

func NewWithHashAndWeights(
	weights map[string]int,
	hashFunc HashFunc,
) *HashRing

func NewWithWeights

func NewWithWeights(weights map[string]int) *HashRing

func (*HashRing) AddNode

func (h *HashRing) AddNode(node string) *HashRing

func (*HashRing) AddWeightedNode

func (h *HashRing) AddWeightedNode(node string, weight int) *HashRing

func (*HashRing) GenKey

func (h *HashRing) GenKey(key string) HashKey

func (*HashRing) GetNode

func (h *HashRing) GetNode(stringKey string) (node string, ok bool)

func (*HashRing) GetNodePos

func (h *HashRing) GetNodePos(stringKey string) (pos int, ok bool)

func (*HashRing) GetNodes

func (h *HashRing) GetNodes(stringKey string, size int) (nodes []string, ok bool)

GetNodes iterates over the hash ring and returns the nodes in the order which is determined by the key. GetNodes is thread safe if the hash which was used to configure the hash ring is thread safe.

func (*HashRing) RemoveNode

func (h *HashRing) RemoveNode(node string) *HashRing

func (*HashRing) Size

func (h *HashRing) Size() int

func (*HashRing) UpdateWeightedNode

func (h *HashRing) UpdateWeightedNode(node string, weight int) *HashRing

func (*HashRing) UpdateWithWeights

func (h *HashRing) UpdateWithWeights(weights map[string]int)

type HashSum

type HashSum struct {
	// contains filtered or unexported fields
}

HashSum allows to use a builder pattern to create different HashFunc objects. See examples for details.

func NewHash

func NewHash(hasher func() hash.Hash) *HashSum

NewHash creates a new *HashSum object which can be used to create HashFunc. HashFunc object is thread safe if the hasher argument produces a new hash.Hash each time. The produced hash.Hash is allowed to be non thread-safe.

func (*HashSum) FirstBytes

func (r *HashSum) FirstBytes(n int) *HashSum

func (*HashSum) LastBytes

func (r *HashSum) LastBytes(n int) *HashSum

func (*HashSum) Use

func (r *HashSum) Use(
	hashKeyFunc func(bytes []byte) (HashKey, error),
) (HashFunc, error)

type Int64PairHashKey

type Int64PairHashKey struct {
	High int64
	Low  int64
}

func (*Int64PairHashKey) Less

func (k *Int64PairHashKey) Less(other HashKey) bool

type Uint32HashKey

type Uint32HashKey uint32

func (Uint32HashKey) Less

func (k Uint32HashKey) Less(other HashKey) bool

Jump to

Keyboard shortcuts

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