Skip to content

vedhavyas/hashring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Consistent Hashing

Consistent hashing is a special kind of hashing such that when a hash table is resized, only K/n keys need to be remapped on average, where K is the number of keys, and n is the number of slots. This academic paper from 1997 introduced the term "consistent hashing" as a way of distributing requests among a changing population of Web servers. Each slot is then represented by a node in a distributed system. The addition (joins) and removal (leaves/failures) of nodes only requires K/n items to be re-shuffled when the number of slots/nodes change

Usage

import "github.com/vedhavyas/hashring"

type HashRing

type HashRing struct {
}

HashRing to hold the nodes and indexes

func New

func New(replicaCount int, hash hash.Hash32) *HashRing

New returns a Hash ring with provided virtual node count and hash If hash is nil, fvn32a is used instead

func (*HashRing) Add

func (hr *HashRing) Add(node string) error

Add adds a node to Hash ring

func (*HashRing) Delete

func (hr *HashRing) Delete(node string) error

Delete deletes the nodes from hash ring

func (*HashRing) Locate

func (hr *HashRing) Get(key string) (node string, err error)

Locate returns the node for a given key

About

Consistent-hashing: Hash ring implementation in Go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages