39 lines
885 B
Go
39 lines
885 B
Go
// 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
|
||
func NewSegment(segmentCnt int) (EasyMap, error) {
|
||
if segmentCnt <= 0 {
|
||
return nil, segmentError()
|
||
}
|
||
em := &segment{
|
||
&common{
|
||
normalDataTable: nil,
|
||
syncMapDataTable: nil,
|
||
dataTableType: normalDataTableType,
|
||
segment: segmentCnt,
|
||
lock: nil,
|
||
},
|
||
}
|
||
em.normalDataTable = make([]map[interface{}]interface{}, segmentCnt)
|
||
for i := 0; i < segmentCnt; i++ {
|
||
em.normalDataTable[i] = make(map[interface{}]interface{})
|
||
}
|
||
em.common.initLock()
|
||
return em, nil
|
||
}
|
||
|
||
type segment struct {
|
||
*common
|
||
}
|