mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
use faster way for siphash (#11640)
This commit is contained in:
parent
9171d6ef65
commit
b690304eed
@ -18,6 +18,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
@ -663,9 +664,11 @@ func sipHashMod(key string, cardinality int, id [16]byte) int {
|
|||||||
if cardinality <= 0 {
|
if cardinality <= 0 {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
sip := siphash.New(id[:])
|
// use the faster version as per siphash docs
|
||||||
sip.Write([]byte(key))
|
// https://github.com/dchest/siphash#usage
|
||||||
return int(sip.Sum64() % uint64(cardinality))
|
k0, k1 := binary.LittleEndian.Uint64(id[0:8]), binary.LittleEndian.Uint64(id[8:16])
|
||||||
|
sum64 := siphash.Hash(k0, k1, []byte(key))
|
||||||
|
return int(sum64 % uint64(cardinality))
|
||||||
}
|
}
|
||||||
|
|
||||||
func crcHashMod(key string, cardinality int) int {
|
func crcHashMod(key string, cardinality int) int {
|
||||||
|
Loading…
Reference in New Issue
Block a user