2021-02-24 14:09:58 +08:00
|
|
|
// Package easymap...
|
|
|
|
//
|
|
|
|
// Description : 内置sync.Map + segment
|
|
|
|
//
|
2021-07-25 19:05:59 +08:00
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
2021-02-24 14:09:58 +08:00
|
|
|
//
|
|
|
|
// Date : 2021-02-24 2:08 下午
|
|
|
|
package easymap
|
2021-02-24 18:19:08 +08:00
|
|
|
|
|
|
|
import (
|
2021-07-25 18:50:56 +08:00
|
|
|
"git.zhangdeman.cn/zhangdeman/gopkg/util"
|
2021-02-24 18:19:08 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewSegmentSync 获取SegmentSync实例
|
|
|
|
//
|
2021-07-25 19:05:59 +08:00
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
2021-02-24 18:19:08 +08:00
|
|
|
//
|
|
|
|
// Date : 6:02 下午 2021/2/24
|
|
|
|
func NewSegmentSync(segment int) (EasyMap, error) {
|
|
|
|
if segment <= 0 {
|
|
|
|
return nil, segmentError()
|
|
|
|
}
|
|
|
|
ss := &segmentSync{
|
|
|
|
segment: segment,
|
|
|
|
}
|
|
|
|
ss.dataTable = make([]EasyMap, segment)
|
|
|
|
for i := 0; i < segment; i++ {
|
|
|
|
ss.dataTable[i] = NewSync()
|
|
|
|
}
|
|
|
|
return ss, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type segmentSync struct {
|
|
|
|
dataTable []EasyMap
|
|
|
|
segment int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) Get(key interface{}) (interface{}, error) {
|
2021-02-24 23:18:29 +08:00
|
|
|
return s.dataTable[util.GetHashIDMod(key, s.segment)].Get(key)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) GetWithReceiver(key interface{}, dest interface{}) error {
|
2021-02-24 23:18:29 +08:00
|
|
|
return s.dataTable[util.GetHashIDMod(key, s.segment)].GetWithReceiver(key, dest)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) GetUint(key interface{}) (uint, error) {
|
2021-02-24 23:18:29 +08:00
|
|
|
return s.dataTable[util.GetHashIDMod(key, s.segment)].GetUint(key)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) GetUint8(key interface{}) (uint8, error) {
|
2021-02-24 23:18:29 +08:00
|
|
|
return s.dataTable[util.GetHashIDMod(key, s.segment)].GetUint8(key)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) GetUint16(key interface{}) (uint16, error) {
|
2021-02-24 23:18:29 +08:00
|
|
|
return s.dataTable[util.GetHashIDMod(key, s.segment)].GetUint16(key)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) GetUint32(key interface{}) (uint32, error) {
|
2021-02-24 23:18:29 +08:00
|
|
|
return s.dataTable[util.GetHashIDMod(key, s.segment)].GetUint32(key)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) GetUint64(key interface{}) (uint64, error) {
|
2021-02-24 23:18:29 +08:00
|
|
|
return s.dataTable[util.GetHashIDMod(key, s.segment)].GetUint64(key)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) GetInt(key interface{}) (int, error) {
|
2021-02-24 23:18:29 +08:00
|
|
|
return s.dataTable[util.GetHashIDMod(key, s.segment)].GetInt(key)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) GetInt8(key interface{}) (int8, error) {
|
2021-02-24 23:18:29 +08:00
|
|
|
return s.dataTable[util.GetHashIDMod(key, s.segment)].GetInt8(key)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) GetInt16(key interface{}) (int16, error) {
|
2021-02-24 23:18:29 +08:00
|
|
|
return s.dataTable[util.GetHashIDMod(key, s.segment)].GetInt16(key)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) GetInt32(key interface{}) (int32, error) {
|
2021-02-24 23:18:29 +08:00
|
|
|
return s.dataTable[util.GetHashIDMod(key, s.segment)].GetInt32(key)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) GetInt64(key interface{}) (int64, error) {
|
2021-02-24 23:18:29 +08:00
|
|
|
return s.dataTable[util.GetHashIDMod(key, s.segment)].GetInt64(key)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) GetFloat32(key interface{}) (float32, error) {
|
2021-02-24 23:18:29 +08:00
|
|
|
return s.dataTable[util.GetHashIDMod(key, s.segment)].GetFloat32(key)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) GetFloat64(key interface{}) (float64, error) {
|
2021-02-24 23:18:29 +08:00
|
|
|
return s.dataTable[util.GetHashIDMod(key, s.segment)].GetFloat64(key)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) GetBool(key interface{}) (bool, error) {
|
2021-02-24 23:18:29 +08:00
|
|
|
return s.dataTable[util.GetHashIDMod(key, s.segment)].GetBool(key)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) GetString(key interface{}) (string, error) {
|
2021-02-24 23:18:29 +08:00
|
|
|
return s.dataTable[util.GetHashIDMod(key, s.segment)].GetString(key)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) Set(key interface{}, value interface{}) {
|
2021-02-24 23:18:29 +08:00
|
|
|
s.dataTable[util.GetHashIDMod(key, s.segment)].Set(key, value)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) Del(key interface{}) {
|
2021-02-24 23:18:29 +08:00
|
|
|
s.dataTable[util.GetHashIDMod(key, s.segment)].Del(key)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) Exist(key interface{}) bool {
|
2021-02-24 23:18:29 +08:00
|
|
|
return s.dataTable[util.GetHashIDMod(key, s.segment)].Exist(key)
|
2021-02-24 18:19:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *segmentSync) GetAll() map[interface{}]interface{} {
|
|
|
|
result := make(map[interface{}]interface{})
|
|
|
|
for i := 0; i < s.segment; i++ {
|
|
|
|
for k, v := range s.dataTable[i].GetAll() {
|
|
|
|
result[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|