升级NewNormal与NewSync

This commit is contained in:
2023-12-14 16:08:59 +08:00
parent 7439281703
commit 68e33b965b
3 changed files with 52 additions and 594 deletions

49
common.go Normal file
View File

@ -0,0 +1,49 @@
// Package easymap ...
//
// Description : easymap ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2023-12-14 15:51
package easymap
import "git.zhangdeman.cn/zhangdeman/util"
// GetShardAndKeyFunc 获取数据所处分片以及key
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:55 2023/12/14
type GetShardAndKeyFunc func(interface{}) (int, interface{})
// DefaultGetShardAndKeyFunc 默认实现
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:57 2023/12/14
func DefaultGetShardAndKeyFunc(key interface{}) GetShardAndKeyFunc {
return func(key interface{}) (int, interface{}) {
return -1, key
}
}
// GetShardAndKeyFuncWithShardCount 获取数据分片和key
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:59 2023/12/14
func GetShardAndKeyFuncWithShardCount(shardCnt int, key interface{}) GetShardAndKeyFunc {
return func(key interface{}) (int, interface{}) {
return util.Hash.GetHashIDMod(key, shardCnt), key
}
}
// common 公共基础结构
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:52 2023/12/14
type common struct {
data map[interface{}]interface{} // 输入数据
GetShardAndKeyFunc GetShardAndKeyFunc // 获取分片以及key的函数
}