Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xiaonanln/go-consistent
Go consistent hashing library
https://github.com/xiaonanln/go-consistent
consistent-hashing consistent-hashing-library murmur
Last synced: about 1 month ago
JSON representation
Go consistent hashing library
- Host: GitHub
- URL: https://github.com/xiaonanln/go-consistent
- Owner: xiaonanln
- License: mit
- Created: 2018-08-20T13:15:04.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-03-16T04:23:49.000Z (almost 4 years ago)
- Last Synced: 2024-10-15T22:07:03.551Z (3 months ago)
- Topics: consistent-hashing, consistent-hashing-library, murmur
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-consistent
go consistent hashing library**It is NOT concurrency safe.**
# Install
```bash
go get github.com/xiaonanln/go-consistent
```# Usage
```go
import "github.com/xiaonanln/go-consistent"// Create Consistent Hashing
c := consistent.New()
// Hash returns ErrNoHost if there are no hosts
c.Hash("key") // returns "", consistent.ErrNoHost
// Add adds a new hash
c.Add("host1")
c.Hash("key") // returns "host1", nilc.Add("host2")
c.Hash("key") // returns "host1"/"host2", nil// SetReplica changes replica. The defualt replica is 20
c.SetReplica(100) // reset replica from 20 to 100
```
# Time complexity
Assuming `N` is number of hosts:
* `Add` = `O(N)`
* `Hash` = `O(log N)`
* `SetReplica` = `O(N)`