fix: Fix concurrent map (#39775)

issue: https://github.com/milvus-io/milvus/issues/39778

Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
This commit is contained in:
yihao.dai 2025-02-22 09:51:54 +08:00 committed by GitHub
parent dd1347d041
commit d72d2281ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 2 deletions

View File

@ -114,7 +114,7 @@ func (m *ConcurrentMap[K, V]) Len() int {
}
func (m *ConcurrentMap[K, V]) Values() []V {
ret := make([]V, m.Len())
ret := make([]V, 0, m.Len())
m.inner.Range(func(key, value any) bool {
ret = append(ret, value.(V))
return true
@ -123,7 +123,7 @@ func (m *ConcurrentMap[K, V]) Values() []V {
}
func (m *ConcurrentMap[K, V]) Keys() []K {
ret := make([]K, m.Len())
ret := make([]K, 0, m.Len())
m.inner.Range(func(key, value any) bool {
ret = append(ret, key.(K))
return true

View File

@ -75,6 +75,9 @@ func (suite *MapUtilSuite) TestConcurrentMap() {
currMap.GetOrInsert(200, "v-200")
currMap.GetOrInsert(300, "v-300")
suite.ElementsMatch([]int64{100, 200, 300}, currMap.Keys())
suite.ElementsMatch([]string{"v-100", "v-200", "v-300"}, currMap.Values())
var exist bool
v, exist = currMap.Get(100)
suite.Equal("v-100", v)