Set will set (or replace) a value for a key. If the key was new, then true will be returned. The returned value will be false if the value was replaced (even if the value was the same).
(key K, value V)
| 42 | // will be returned. The returned value will be false if the value was replaced |
| 43 | // (even if the value was the same). |
| 44 | func (m *OrderedMap[K, V]) Set(key K, value V) bool { |
| 45 | _, alreadyExist := m.kv[key] |
| 46 | if alreadyExist { |
| 47 | m.kv[key].Value = value |
| 48 | return false |
| 49 | } |
| 50 | |
| 51 | element := m.ll.PushBack(key, value) |
| 52 | m.kv[key] = element |
| 53 | return true |
| 54 | } |
| 55 | |
| 56 | // ReplaceKey replaces an existing key with a new key while preserving order of |
| 57 | // the value. This function will return true if the operation was successful, or |