Store stores the value in the map for the key, overwriting the previous value if the key exists.
(key K, value V)
| 75 | |
| 76 | // Store stores the value in the map for the key, overwriting the previous value if the key exists. |
| 77 | func (m *OrderedMap[K, V]) Store(key K, value V) { |
| 78 | m.rehydrate() |
| 79 | |
| 80 | if p := m.inner[key]; p != nil { |
| 81 | p.Value = value |
| 82 | return |
| 83 | } |
| 84 | p := &Pair[K, V]{Key: key, Value: value} |
| 85 | m.Pairs = append(m.Pairs, p) |
| 86 | m.inner[key] = p |
| 87 | } |
| 88 | |
| 89 | // rehydrate ensures that the inner map is up-to-date with the Pairs slice. This can happen when |
| 90 | // the OrderedMap is serialized and deserialized via gob encoding (the inner map is unexported and |