mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
fix(orderedmap): fix set bug (#252)
set : when the key is present, the value of the data map should be set, not the value of the list Co-authored-by: congziqi <congziqi@lixiang.com>
This commit is contained in:
@@ -35,7 +35,7 @@ func (om *OrderedMap[K, V]) Set(key K, value V) {
|
|||||||
defer om.mu.Unlock()
|
defer om.mu.Unlock()
|
||||||
|
|
||||||
if elem, ok := om.index[key]; ok {
|
if elem, ok := om.index[key]; ok {
|
||||||
elem.Value = value
|
om.data[key] = value
|
||||||
om.order.MoveToBack(elem)
|
om.order.MoveToBack(elem)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ func TestOrderedMap_Set_Get(t *testing.T) {
|
|||||||
assert.Equal(1, val)
|
assert.Equal(1, val)
|
||||||
assert.Equal(true, ok)
|
assert.Equal(true, ok)
|
||||||
|
|
||||||
|
om.Set("a", 2)
|
||||||
|
val, _ = om.Get("a")
|
||||||
|
assert.Equal(2, val)
|
||||||
|
|
||||||
val, ok = om.Get("d")
|
val, ok = om.Get("d")
|
||||||
assert.Equal(false, ok)
|
assert.Equal(false, ok)
|
||||||
assert.Equal(0, val)
|
assert.Equal(0, val)
|
||||||
|
|||||||
Reference in New Issue
Block a user