consistenthash

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: MIT Imports: 4 Imported by: 0

README

consistenthash

This library implements consistent hash introduced in this paper. This library is for learning purposes only.

Checkout this blog post for more info.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNodeNotFound = errors.New("node not found")

Functions

This section is empty.

Types

type Node

type Node struct {
	Id     string
	HashId uint32
}

Node is a single entity in a ring.

func NewNode

func NewNode(id string) *Node

type Nodes

type Nodes []*Node

func (Nodes) Len

func (n Nodes) Len() int

Nodes implement sort.Interface.

func (Nodes) Less

func (n Nodes) Less(i, j int) bool

func (Nodes) Swap

func (n Nodes) Swap(i, j int)

type Ring

type Ring struct {
	Nodes Nodes

	sync.RWMutex
}

Ring is a network of distributed nodes.

func NewRing

func NewRing() *Ring

func (*Ring) AddNode

func (r *Ring) AddNode(id string)

func (*Ring) Get

func (r *Ring) Get(key string) string

Get returns the node closest to the key specified as argument, from the nodes ring.

func (*Ring) RemoveNode

func (r *Ring) RemoveNode(id string) error

Jump to

Keyboard shortcuts

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