Skip to content

pkumza/consistent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

consistent

Consistent hash package for Go.

Performance is better than stathat.com/c/consistent, but no concurrence guarantee.

NumOfReplicas of each shard is adjustable.

Installation

go get github.com/pkumza/consistent@latest

Docs

https://godoc.org/github.com/pkumza/consistent

Example

	c := New()
	c.Add("Bucket1", 20)
	c.Add("Bucket2", 40)
	c.SortHashes()
	bucket, _ := c.Get("apple")
	fmt.Println(bucket) // Bucket2
	bucket, _ = c.Get("banana")
	fmt.Println(bucket) // Bucket1
	bucket, _ = c.Get("pear")
	fmt.Println(bucket) // Bucket2