Skip to content

Commit cb08613

Browse files
congziqi77congziqi
andauthored
fix(orderedmap): fix set bug (duke-git#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 <[email protected]>
1 parent 213e2b4 commit cb08613

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

maputil/orderedmap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (om *OrderedMap[K, V]) Set(key K, value V) {
3535
defer om.mu.Unlock()
3636

3737
if elem, ok := om.index[key]; ok {
38-
elem.Value = value
38+
om.data[key] = value
3939
om.order.MoveToBack(elem)
4040

4141
return

maputil/orderedmap_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ func TestOrderedMap_Set_Get(t *testing.T) {
1919
assert.Equal(1, val)
2020
assert.Equal(true, ok)
2121

22+
om.Set("a", 2)
23+
val, _ = om.Get("a")
24+
assert.Equal(2, val)
25+
2226
val, ok = om.Get("d")
2327
assert.Equal(false, ok)
2428
assert.Equal(0, val)

0 commit comments

Comments
 (0)