ringhash

package
Version: v0.17.10 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: GPL-3.0 Imports: 6 Imported by: 1

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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.

Source Files

Jump to

Keyboard shortcuts

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