rendezvous

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

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

Go to latest
Published: Jan 22, 2022 License: MIT Imports: 5 Imported by: 0

README

rendezvous-hashing-go

Rendezvous Hashing in Golang

This library provides an implementation of Weighted Rendezvous Hashing.

For more details about Rendezvous Hashing and its weighted variants see:

The implementation is meant to be threadsafe.

Credit

This library is heavily inspired by this already excellent consistent hashing library. This library's interface is heavily derivative of the above mention library's. If you dive into the code you will see many similarities between the two libraries.

The implementation of the Rendezvous Hashing algorithm is the same as the one outlined here https://en.wikipedia.org/wiki/Rendezvous_hashing#Weighted_rendezvous_hash.

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInsufficientMemberCount = consistent.ErrInsufficientMemberCount
View Source
var FiftyThreeOnes = uint64(0xFFFFFFFFFFFFFFFF >> (64 - 53))
View Source
var FiftyThreeZeros = float64(1 << 53)

Functions

func IntToFloat

func IntToFloat(value uint64) (float_value float64)

IntToFloat is a golang port of the python implementation mentioned here https://en.wikipedia.org/wiki/Rendezvous_hashing#Weighted_rendezvous_hash

Types

type Config

type Config struct {
	Hasher Hasher
}

Config represents a structure to control the rendezvous package.

type DefaultHasher

type DefaultHasher struct {
}

func (*DefaultHasher) Sum64

func (h *DefaultHasher) Sum64(b []byte) uint64

type Hasher

type Hasher consistent.Hasher

type Rendezvous

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

Rendezvous holds the information about the members of the consistent hash circle.

func New

func New(members []WeightedMember, config Config) *Rendezvous

New creates and returns a new Rendezvous object

func (*Rendezvous) Add

func (r *Rendezvous) Add(member WeightedMember)

func (*Rendezvous) ComputeWeightedScore

func (r *Rendezvous) ComputeWeightedScore(m WeightedMember, key []byte) (score float64)

func (*Rendezvous) GetClosestN

func (r *Rendezvous) GetClosestN(key []byte, count int) (members []WeightedMember, err error)

GetClosestN returns the closest N members to the key, the members returned is not sorted

func (*Rendezvous) GetMembers

func (r *Rendezvous) GetMembers() (members []WeightedMember)

GetMembers returns a thread-safe copy of members.

func (*Rendezvous) LocateKey

func (r *Rendezvous) LocateKey(key []byte) (member WeightedMember)

func (*Rendezvous) Remove

func (r *Rendezvous) Remove(name string)

type WeightedMember

type WeightedMember interface {
	consistent.Member
	Weight() float64
}

Jump to

Keyboard shortcuts

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