2022-05-14 16:07:21 +08:00
|
|
|
|
// Package easymap ...
|
|
|
|
|
//
|
|
|
|
|
// Description : 分段存储的map,并发行更好,分段数量为 1, 将退化成普通的
|
|
|
|
|
//
|
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
|
//
|
|
|
|
|
// Date : 2021-02-23 10:47 下午
|
|
|
|
|
package easymap
|
|
|
|
|
|
|
|
|
|
// NewSegment 获取分段map实例
|
|
|
|
|
//
|
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
|
//
|
|
|
|
|
// Date : 11:05 下午 2021/2/24
|
2023-12-24 22:10:47 +08:00
|
|
|
|
func NewSegment(segmentCnt int) (EasyMap, error) {
|
2022-05-14 16:07:21 +08:00
|
|
|
|
if segmentCnt <= 0 {
|
|
|
|
|
return nil, segmentError()
|
|
|
|
|
}
|
|
|
|
|
em := &segment{
|
2023-12-24 22:44:07 +08:00
|
|
|
|
&common{
|
|
|
|
|
normalDataTable: nil,
|
|
|
|
|
syncMapDataTable: nil,
|
|
|
|
|
dataTableType: normalDataTableType,
|
|
|
|
|
segment: segmentCnt,
|
|
|
|
|
lock: nil,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
em.normalDataTable = make([]map[interface{}]interface{}, segmentCnt)
|
2022-05-14 16:07:21 +08:00
|
|
|
|
for i := 0; i < segmentCnt; i++ {
|
2023-12-24 22:44:07 +08:00
|
|
|
|
em.normalDataTable[i] = make(map[interface{}]interface{})
|
2022-05-14 16:07:21 +08:00
|
|
|
|
}
|
2023-12-24 22:10:47 +08:00
|
|
|
|
em.common.initLock()
|
2022-05-14 16:07:21 +08:00
|
|
|
|
return em, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type segment struct {
|
2023-12-24 22:44:07 +08:00
|
|
|
|
*common
|
2023-08-15 20:46:43 +08:00
|
|
|
|
}
|