@@ -34,13 +34,15 @@ func (o *OrderedMapIntFloat64) Get(key int) (float64, bool) {
3434return val , exists
3535}
3636
37- // Set will set a key and value pair. It will over-write an
37+ // Set will set a key and value pair. It will overwrite an
3838// existing pair if it exists already.
3939func (o * OrderedMapIntFloat64 ) Set (key int , val float64 ) {
40- o .store [key ] = val
4140if o .keys != nil {
42- o .keys = append (o .keys , key )
41+ if _ , exists := o .store [key ]; ! exists {
42+ o .keys = append (o .keys , key )
43+ }
4344}
45+ o .store [key ] = val
4446}
4547
4648// Delete will remove the key from the OrderedMapIntFloat64.
@@ -63,7 +65,9 @@ func (o *OrderedMapIntFloat64) Delete(key int) {
6365break
6466}
6567}
66- o .keys = append (o .keys [:* idx ], o .keys [* idx + 1 :]... )
68+ if idx != nil {
69+ o .keys = append (o .keys [:* idx ], o .keys [* idx + 1 :]... )
70+ }
6771}
6872
6973// ValuesIterator is used to iterate through the values of OrderedMapIntFloat64.
@@ -121,13 +125,15 @@ func (o *OrderedMapIntMixed) Get(key int) (interface{}, bool) {
121125return val , exists
122126}
123127
124- // Set will set a key and value pair. It will over-write an
128+ // Set will set a key and value pair. It will overwrite an
125129// existing pair if it exists already.
126130func (o * OrderedMapIntMixed ) Set (key int , val interface {}) {
127- o .store [key ] = val
128131if o .keys != nil {
129- o .keys = append (o .keys , key )
132+ if _ , exists := o .store [key ]; ! exists {
133+ o .keys = append (o .keys , key )
134+ }
130135}
136+ o .store [key ] = val
131137}
132138
133139// Delete will remove the key from the OrderedMapIntMixed.
@@ -150,7 +156,9 @@ func (o *OrderedMapIntMixed) Delete(key int) {
150156break
151157}
152158}
153- o .keys = append (o .keys [:* idx ], o .keys [* idx + 1 :]... )
159+ if idx != nil {
160+ o .keys = append (o .keys [:* idx ], o .keys [* idx + 1 :]... )
161+ }
154162}
155163
156164// ValuesIterator is used to iterate through the values of OrderedMapIntMixed.
0 commit comments