增加计算元素数量方法

This commit is contained in:
白茶清欢 2024-01-30 14:22:51 +08:00
parent 804bc98227
commit a87a97b0e8
2 changed files with 16 additions and 0 deletions

View File

@ -32,6 +32,7 @@ type EasyMap interface {
Set(key interface{}, value interface{}) Set(key interface{}, value interface{})
Del(key interface{}) Del(key interface{})
Exist(key interface{}) bool Exist(key interface{}) bool
Count() int
GetAll() map[interface{}]interface{} GetAll() map[interface{}]interface{}
GetAllForMapKeyString() map[string]interface{} GetAllForMapKeyString() map[string]interface{}
// Iterator 对数据的迭代 // Iterator 对数据的迭代

View File

@ -269,6 +269,21 @@ func (c *common) Exist(key interface{}) bool {
return exist 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{} { func (c *common) GetAll() map[interface{}]interface{} {
result := make(map[interface{}]interface{}) result := make(map[interface{}]interface{})
c.RLock() c.RLock()