From a87a97b0e8d48ea643998e0aaab1eaca9a6ba5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 30 Jan 2024 14:22:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=A1=E7=AE=97=E5=85=83?= =?UTF-8?q?=E7=B4=A0=E6=95=B0=E9=87=8F=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abstruct.go | 1 + common.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+) 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()