hashring

package module
v0.0.0-...-aea95f1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2017 License: Unlicense Imports: 5 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HashRing

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

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) Locate(key string) (node string, err error)

Locate returns the node for a given key

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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