v0.0.0-...-440800f Latest Latest

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

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



Package ringhash implementats a consistent ring hash: https://en.wikipedia.org/wiki/Consistent_hashing



This section is empty.


This section is empty.


This section is empty.


type Hash

type Hash func(data []byte) uint32

Hash is a signature of a hash function used by the package.

type Ring

type Ring struct {
	// contains filtered or unexported fields

Ring is the definition of the ringhash.

func New

func New(replicas int, fn Hash) *Ring

New initializes an empty ringhash with the given number of replicas and a hash function. If the hash function is nil, crc32.NewIEEE() is used.

func (*Ring) Add

func (ring *Ring) Add(keys ...string)

Add adds keys to the ring.

func (*Ring) Get

func (ring *Ring) Get(key string) string

Get returns the closest item in the ring to the provided key.

func (*Ring) Len

func (ring *Ring) Len() int

Len returns the number of keys in the ring.

func (*Ring) Signature

func (ring *Ring) Signature() string

Signature returns the ring's hash signature. Two identical ringhashes will have the same signature. Two hashes with different number of keys or replicas or hash functions will have different signatures.

Jump to

Keyboard shortcuts

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