easymap/sync_segment.go

43 lines
804 B
Go
Raw Normal View History

2022-05-14 16:07:21 +08:00
// Package easymap...
//
// Description : 内置sync.Map + segment
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2021-02-24 2:08 下午
package easymap
import (
2023-12-24 22:44:07 +08:00
"sync"
2022-05-14 16:07:21 +08:00
)
// NewSegmentSync 获取SegmentSync实例
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 6:02 下午 2021/2/24
func NewSegmentSync(segment int) (EasyMap, error) {
if segment <= 0 {
return nil, segmentError()
}
ss := &segmentSync{
2023-12-24 22:44:07 +08:00
&common{
normalDataTable: nil,
syncMapDataTable: nil,
dataTableType: syncMapDataTableType,
segment: segment,
lock: nil,
},
}
ss.syncMapDataTable = make([]sync.Map, segment)
2022-05-14 16:07:21 +08:00
for i := 0; i < segment; i++ {
2023-12-24 22:44:07 +08:00
ss.syncMapDataTable[i] = sync.Map{}
2022-05-14 16:07:21 +08:00
}
2023-12-24 22:44:07 +08:00
ss.initLock()
2022-05-14 16:07:21 +08:00
return ss, nil
}
type segmentSync struct {
2023-12-24 22:44:07 +08:00
*common
2023-08-15 20:46:43 +08:00
}