https://github.com/vedhavyas/hashring
Consistent-hashing: Hash ring implementation in Go
https://github.com/vedhavyas/hashring
consistent-hashing consistent-hashing-library hashring
Last synced: 4 months ago
JSON representation
Consistent-hashing: Hash ring implementation in Go
- Host: GitHub
- URL: https://github.com/vedhavyas/hashring
- Owner: vedhavyas
- License: unlicense
- Created: 2017-12-14T14:51:45.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-06-28T11:43:04.000Z (almost 5 years ago)
- Last Synced: 2024-06-20T02:09:48.894Z (12 months ago)
- Topics: consistent-hashing, consistent-hashing-library, hashring
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 30
- Watchers: 4
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
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
```go
type HashRing struct {
}
```HashRing to hold the nodes and indexes
#### func New
```go
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
```go
func (hr *HashRing) Add(node string) error
```
Add adds a node to Hash ring#### func (*HashRing) Delete
```go
func (hr *HashRing) Delete(node string) error
```
Delete deletes the nodes from hash ring#### func (*HashRing) Locate
```go
func (hr *HashRing) Get(key string) (node string, err error)
```
Locate returns the node for a given key