hash

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TopWeight is the maximum weight for a node in the consistent hashing ring.
	TopWeight = 100
)

Variables

This section is empty.

Functions

func Hash

func Hash(data []byte) uint64

Hash returns the hash value of data.

Types

type Consistent

type Consistent interface {
	Add(node string) error
	AddWithReplicas(node string, replicas int) error
	AddWithWeight(node string, weight int) error
	Get(v string) (string, *grpc.ClientConn, bool)
	Remove(node string) error
	AddKey(key string) bool
}

Consistent is an interface for a consistent hash ring

type ConsistentHash

type ConsistentHash struct {
	Nodes map[string]*grpc.ClientConn // Node addresses mapped to their gRPC client connections
	// contains filtered or unexported fields
}

ConsistentHash implements a consistent hashing ring

func NewConsistentHash

func NewConsistentHash(replicas int, fn Func, connOpts config.GRPC) (*ConsistentHash, error)

NewConsistentHash creates a new consistent hash ring

func (*ConsistentHash) Add

func (h *ConsistentHash) Add(node string) error

Add adds a node to the hash ring with the default number of replicas

func (*ConsistentHash) AddKey

func (h *ConsistentHash) AddKey(key string) bool

AddKey adds a key to the hash ring and assigns it to a node

func (*ConsistentHash) AddWithReplicas

func (h *ConsistentHash) AddWithReplicas(node string, replicas int) error

AddWithReplicas adds a node to the hash ring with a specified number of replicas

func (*ConsistentHash) AddWithWeight

func (h *ConsistentHash) AddWithWeight(node string, weight int) error

AddWithWeight adds a node to the hash ring with a number of replicas proportional to its weight

func (*ConsistentHash) Get

Get returns the node responsible for the hash of the given key and its gRPC connection

func (*ConsistentHash) Remove

func (h *ConsistentHash) Remove(node string) error

Remove removes a node from the hash ring

type Func

type Func func(data []byte) uint64

Func is a type representing a hashing function that accepts a byte slice and returns an uint64 hash

Jump to

Keyboard shortcuts

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