2022-05-14 13:45:51 +08:00
|
|
|
// Package util...
|
|
|
|
//
|
|
|
|
// Description : util...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 2021-02-24 11:04 下午
|
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spaolacci/murmur3"
|
|
|
|
)
|
|
|
|
|
2022-05-14 14:45:14 +08:00
|
|
|
// hash ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 14:41 2022/5/14
|
|
|
|
type hash struct {
|
|
|
|
}
|
|
|
|
|
2022-05-14 13:45:51 +08:00
|
|
|
// GetHashID ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 11:04 下午 2021/2/24
|
2022-05-14 14:45:14 +08:00
|
|
|
func (h *hash) GetHashID(key interface{}) uint64 {
|
2022-05-14 13:45:51 +08:00
|
|
|
return murmur3.Sum64([]byte(fmt.Sprintf("%v", key)))
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetHashIDMod 获取hashID并取模
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 11:07 下午 2021/2/24
|
2022-05-14 14:45:14 +08:00
|
|
|
func (h *hash) GetHashIDMod(key interface{}, shard int) int {
|
|
|
|
return int(h.GetHashID(key) % uint64(shard))
|
2022-05-14 13:45:51 +08:00
|
|
|
}
|