ring

package
v0.0.0-...-0046ca6 Latest Latest
Warning

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

Go to latest
Published: May 5, 2018 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element struct {
	Value interface{}
}

Element defines an element of the ring.

type Hasher

type Hasher interface {
	// Hash returns a 32-bit checksum of the type.
	Hash() uint32
}

Hasher describes hashable types. In other words, such types that can be used as keys of the hash-table.

type Ring

type Ring interface {
	// Insert inserts a new element into a ring. After the insertion,
	// the partition assignments will be re-calculated.
	Insert(*Element)

	// Remove removes element from the ring. After the remove, the
	// partition assignments will be re-calculated.
	Remove(*Element)

	// Find searches for element, that is assigned to the given key.
	Find(Hasher) *Element
}

Ring describes types that implement a ring container.

The ring is an implementation of consistent hashing algorithm used for equal balancing of the data between multiple database shards.

func New

func New(ratio int) Ring

New creates a new instance of the consistent-hashing ring.

type StringHasher

type StringHasher string

StringHasher is an implementation of the Hasher interface that calculates Fowler-Noll-Vo checksum of the string.

func (StringHasher) Hash

func (h StringHasher) Hash() uint32

Hash implement Hasher interface.

Jump to

Keyboard shortcuts

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