Some optimizations for HRW sort #8

Merged
fyrchik merged 1 commit from fyrchik/hrw:optimize-hrw into master 2023-07-26 21:08:01 +00:00
2 changed files with 6 additions and 1 deletions

5
hrw.go
View file

@ -68,6 +68,11 @@ func Hash(key []byte) uint64 {
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
func Sort(nodes []uint64, hash uint64) []uint64 {
l := len(nodes)

View file

@ -61,7 +61,7 @@ func Example() {
}
func (h hashString) Hash() uint64 {
return Hash([]byte(h))
return StringHash(string(h))
}
func TestSortSliceByIndex(t *testing.T) {