easymap/segment.go
2023-12-24 22:44:07 +08:00

39 lines
885 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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
}