Some optimizations for HRW sort #8
2 changed files with 6 additions and 1 deletions
5
hrw.go
5
hrw.go
|
@ -68,6 +68,11 @@ func Hash(key []byte) uint64 {
|
||||||
return murmur3.Sum64(key)
|
return murmur3.Sum64(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StringHash uses murmur3 hash to return uint64
|
||||||
|
func StringHash(key string) uint64 {
|
||||||
|
return murmur3.StringSum64(key)
|
||||||
|
}
|
||||||
|
|
||||||
// Sort receive nodes and hash, and sort it by distance
|
// Sort receive nodes and hash, and sort it by distance
|
||||||
func Sort(nodes []uint64, hash uint64) []uint64 {
|
func Sort(nodes []uint64, hash uint64) []uint64 {
|
||||||
l := len(nodes)
|
l := len(nodes)
|
||||||
|
|
|
@ -61,7 +61,7 @@ func Example() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h hashString) Hash() uint64 {
|
func (h hashString) Hash() uint64 {
|
||||||
return Hash([]byte(h))
|
return StringHash(string(h))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSortSliceByIndex(t *testing.T) {
|
func TestSortSliceByIndex(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue