diff --git a/abstruct.go b/abstruct.go index 0a36f42..e970f34 100644 --- a/abstruct.go +++ b/abstruct.go @@ -32,6 +32,7 @@ type EasyMap interface { Set(key interface{}, value interface{}) Del(key interface{}) Exist(key interface{}) bool + Count() int GetAll() map[interface{}]interface{} GetAllForMapKeyString() map[string]interface{} // Iterator 对数据的迭代 diff --git a/common.go b/common.go index 2d27e92..d8ca79f 100644 --- a/common.go +++ b/common.go @@ -269,6 +269,21 @@ func (c *common) Exist(key interface{}) bool { return exist } +// Count 计算元素数量 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:21 2024/1/30 +func (c *common) Count() int { + cnt := 0 + c.RLock() + defer c.RUnlock() + for i := 0; i < c.segment; i++ { + cnt = cnt + len(c.normalDataTable[i]) + } + return cnt +} + func (c *common) GetAll() map[interface{}]interface{} { result := make(map[interface{}]interface{}) c.RLock()