consistenthash

package module
v0.0.0-...-590a14e Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2017 License: BSD-3-Clause Imports: 3 Imported by: 0

README

License BSD Go Report Card GoDoc Build Status

consistenthash

consistenthash is an implementation of a consistent hash in Go

This technique is explained in these links:

http://en.wikipedia.org/wiki/Consistent_hashing

http://www.tomkleinpeter.com/2008/03/17/programmers-toolbox-part-3-consistent-hashing/

There is also a popular existing quality Go implementation here:

https://github.com/stathat/consistent

This package is not a copy of that and was developed clean-room from the wikipedia article. Check out that link also if you are evaluating software to provide this functionality.

Documentation

Overview

Package consistenthash implements a consistent hash.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsistentHash

type ConsistentHash struct {
	// to enter elements into the hash multiple times
	Mult int
	// the sorted list of hashed elements
	SumList []uint32
	// a map of hash values to original strings
	Source (map[uint32]string)
}

ConsistentHash maps hashed values to targets.

func New

func New(mult int) (*ConsistentHash, error)

New is an alias to NewConsistentHash.

func NewConsistentHash

func NewConsistentHash(mult int) (*ConsistentHash, error)

NewConsistentHash will create a new consistent hash with hashed elements multiplied and entered into the SumList "mult" times.

func (*ConsistentHash) Find

func (h *ConsistentHash) Find(s string) (string, error)

Find the nearest hashed element (in ascending order) that the candidate string s maps to. should s hash to a greater value than the maximum hashed item in the SumList, loop around and select the zeroth hashed element

func (*ConsistentHash) Insert

func (h *ConsistentHash) Insert(s string) error

Insert a new element into the SumList as "mult" instances of crc32 hashes.

func (*ConsistentHash) Remove

func (h *ConsistentHash) Remove(s string) error

Remove a new element from the SumList as "mult" instances of crc32 hashes.

Jump to

Keyboard shortcuts

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