mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-06 17:18:35 +08:00
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:
parent
dd1347d041
commit
d72d2281ca
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user