dgryski / go-ketama Goto Github PK
View Code? Open in Web Editor NEWKetama implementation compatible with Algorithm::ConsistentHash::Ketama
Ketama implementation compatible with Algorithm::ConsistentHash::Ketama
It is possible to create a bucket with negative weight leading to this module not mapping anything:
package main
import (
"fmt"
"github.com/dgryski/go-ketama"
)
func main() {
var buckets []ketama.Bucket
buckets = append(buckets, ketama.Bucket{"127.0.0.1", -300})
buckets = append(buckets, ketama.Bucket{"127.0.0.1:11212", 200})
buckets = append(buckets, ketama.Bucket{"127.0.0.1:11213", 100})
fmt.Println(buckets)
c, _ := ketama.New(buckets)
tests := []string{
"thing1",
"thing2",
"thing3",
"thing4",
"thing5",
"thing6",
"thing7",
"thing8",
"thing9",
"thing0",
"thinga",
"thingb",
"thingc",
"thingd",
}
for _, test := range tests {
fmt.Printf("%q -> %q\n", test, c.Hash(test))
}
}
when executed:
+ $ go run git.sr.ht/~graywolf/gomemcache/foo
[{127.0.0.1 -300} {127.0.0.1:11212 200} {127.0.0.1:11213 100}]
"thing1" -> ""
"thing2" -> ""
"thing3" -> ""
"thing4" -> ""
"thing5" -> ""
"thing6" -> ""
"thing7" -> ""
"thing8" -> ""
"thing9" -> ""
"thing0" -> ""
"thinga" -> ""
"thingb" -> ""
"thingc" -> ""
"thingd" -> ""
Since weight <= 0 does not really make sense, I would propose New()
to return an error if such a weight is provided. If you agree I can prepare a patch.
This package does not use go modules, would you accept pull request adding go.mod
file?
After lestrrat-p5/Algorithm-ConsistentHash-Ketama@1efbcc0 , the behaviour of the binary search in the XS file and sort.Search() differ.
I'm not sure if the fix is to push a different binary search to the Perl library or to stop using sort.Search() and replace it with a translation of the C code.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.