forked from TrueCloudLab/hrw
[#8] hrw: Introduce StringHash() for hashing strings directly
``` goos: linux goarch: amd64 pkg: git.frostfs.info/TrueCloudLab/hrw cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz │ 6 │ 7 │ │ sec/op │ sec/op vs base │ SortHashersByValue_Typed_fnv_10-8 248.8n ± 1% 166.9n ± 9% -32.93% (p=0.000 n=10) SortHashersByValue_Typed_fnv_100-8 2.195µ ± 6% 1.297µ ± 6% -40.93% (p=0.000 n=10) SortHashersByValue_Typed_fnv_1000-8 22.47µ ± 4% 12.42µ ± 10% -44.73% (p=0.000 n=10) SortHashersByWeightValueTyped_fnv_10-8 301.7n ± 6% 180.8n ± 4% -40.09% (p=0.000 n=10) SortHashersByWeightValueTyped_fnv_100-8 2.526µ ± 1% 1.378µ ± 5% -45.47% (p=0.000 n=10) SortHashersByWeightValueTyped_fnv_1000-8 24.37µ ± 2% 12.80µ ± 4% -47.48% (p=0.000 n=10) geomean 2.472µ 1.430µ -42.13% │ 6 │ 7 │ │ B/op │ B/op vs base │ SortHashersByValue_Typed_fnv_10-8 144.0 ± 0% 144.0 ± 0% ~ (p=1.000 n=10) ¹ SortHashersByValue_Typed_fnv_100-8 960.0 ± 0% 960.0 ± 0% ~ (p=1.000 n=10) ¹ SortHashersByValue_Typed_fnv_1000-8 8.062Ki ± 0% 8.062Ki ± 0% ~ (p=1.000 n=10) ¹ SortHashersByWeightValueTyped_fnv_10-8 144.0 ± 0% 144.0 ± 0% ~ (p=1.000 n=10) ¹ SortHashersByWeightValueTyped_fnv_100-8 960.0 ± 0% 960.0 ± 0% ~ (p=1.000 n=10) ¹ SortHashersByWeightValueTyped_fnv_1000-8 8.062Ki ± 0% 8.062Ki ± 0% ~ (p=1.000 n=10) ¹ geomean 1.021Ki 1.021Ki +0.00% ¹ all samples are equal │ 6 │ 7 │ │ allocs/op │ allocs/op vs base │ SortHashersByValue_Typed_fnv_10-8 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=10) ¹ SortHashersByValue_Typed_fnv_100-8 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=10) ¹ SortHashersByValue_Typed_fnv_1000-8 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=10) ¹ SortHashersByWeightValueTyped_fnv_10-8 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=10) ¹ SortHashersByWeightValueTyped_fnv_100-8 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=10) ¹ SortHashersByWeightValueTyped_fnv_1000-8 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=10) ¹ geomean 2.000 2.000 +0.00% ¹ all samples are equal ``` Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
2ac89c82b6
commit
16a7740ccd
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