mobius

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2019 License: MIT Imports: 3 Imported by: 0

README

Mobius

Build Status Code Coverage Latest Version GoDoc Go Report Card

Mobius provides a consistent-hashing algorithm for Go, designed to allocate work across a set of members of a cluster.

Documentation

Overview

Package mobius provides a consistent-hashing algorithm designed to allocate work across a set of members of a cluster.

Index

Constants

View Source
const DefaultWeightMultiplier uint32 = 100

DefaultWeightMultiplier is default value to use for Ring.WeightMultiplier if it is zero.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ring

type Ring struct {
	// WeightMultiplier is the number that each member's weight is multiplied by
	// to produce the number of vnodes to add for each member. If it zero
	// DefaultWeightMultiplier is used.
	WeightMultiplier uint32
	// contains filtered or unexported fields
}

Ring is a consistent-hashing ring.

It is a set-like collection that allows efficient, consisting mapping of arbitrary keys to the members of the set with minimum redistribution of these mappings when set membership is changed.

func (*Ring) Add

func (d *Ring) Add(m string, k []byte, w uint32) bool

Add adds a member to the ring.

m uniquely identifies the member.

k is the value that is hashed to determine where the member is placed within the ring.

w is the member's relative weight, which controls the proportion of the ring that is assigned to this member. A member with a weight of 2 occupies twice the space on the ring as a member with a weight of 1.

It returns false is m is already a member of the ring.

func (*Ring) Get

func (d *Ring) Get(k []byte) (m string, ok bool)

Get returns the member from the ring that k maps.

func (*Ring) Ordered

func (d *Ring) Ordered(k []byte) []string

Ordered returns all members on the ring, ordered according to their distance from k.

The first element is the same as the value returned by Get(). Each subsequent element is the member that would have been returned by Get() had the element before it had not been a member of the ring.

func (*Ring) Remove

func (d *Ring) Remove(m string) bool

Remove removes a member from the ring.

It returns false if m is not a member of the ring.

Jump to

Keyboard shortcuts

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