From 8fae26e662a580c767fc9292f4274e704fb0ad1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 14 May 2022 14:45:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0hash=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hash.go | 14 +++++++++++--- init.go | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/hash.go b/hash.go index 9d10327..ffd1bda 100644 --- a/hash.go +++ b/hash.go @@ -13,12 +13,20 @@ import ( "github.com/spaolacci/murmur3" ) +// hash ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:41 2022/5/14 +type hash struct { +} + // GetHashID ... // // Author : go_developer@163.com<白茶清欢> // // Date : 11:04 下午 2021/2/24 -func GetHashID(key interface{}) uint64 { +func (h *hash) GetHashID(key interface{}) uint64 { return murmur3.Sum64([]byte(fmt.Sprintf("%v", key))) } @@ -27,6 +35,6 @@ func GetHashID(key interface{}) uint64 { // Author : go_developer@163.com<白茶清欢> // // Date : 11:07 下午 2021/2/24 -func GetHashIDMod(key interface{}, shard int) int { - return int(GetHashID(key) % uint64(shard)) +func (h *hash) GetHashIDMod(key interface{}, shard int) int { + return int(h.GetHashID(key) % uint64(shard)) } diff --git a/init.go b/init.go index e5b69ca..e13e1fa 100644 --- a/init.go +++ b/init.go @@ -12,9 +12,12 @@ var ( Cli *cli // File ... File *file + // Hash ... + Hash *hash ) func init() { Cli = &cli{} File = &file{} + Hash = &hash{} }