consistenthash

package
v0.0.0-...-60f325a Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package consistenthash provides an implementation of a ring hash.

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 maps the data to a uint32 hash-ring

type Map

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

Map tracks segments in a hash-ring, mapped to specific keys.

func New

func New(segsPerKey int, fn Hash) *Map

New constructs a new consistenthash hashring, with segsPerKey segments per added key.

func (*Map) Add

func (m *Map) Add(keys ...string)

Add adds some keys to the hashring, establishing ownership of segsPerKey segments.

func (*Map) Get

func (m *Map) Get(key string) string

Get gets the closest item in the hash to the provided key.

func (*Map) GetReplicated

func (m *Map) GetReplicated(key string, keyReplicas int) []string

GetReplicated gets the closest item in the hash to a deterministic set of keyReplicas variations of the provided key. The returned set of segment-owning keys is dedup'd, and collisions are resolved by traversing backwards in the hash-ring to find an unused owning-key.

func (*Map) IsEmpty

func (m *Map) IsEmpty() bool

IsEmpty returns true if there are no items available.

Jump to

Keyboard shortcuts

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