diff --git a/hrw.go b/hrw.go index 9059636..1156037 100644 --- a/hrw.go +++ b/hrw.go @@ -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) diff --git a/hrw_test.go b/hrw_test.go index 934e335..bb22c81 100644 --- a/hrw_test.go +++ b/hrw_test.go @@ -61,7 +61,7 @@ func Example() { } func (h hashString) Hash() uint64 { - return Hash([]byte(h)) + return StringHash(string(h)) } func TestSortSliceByIndex(t *testing.T) {