Sets the given value under the specified key if no value was associated with it.
(key string, value interface{})
| 115 | |
| 116 | // Sets the given value under the specified key if no value was associated with it. |
| 117 | func (m ConcurrentHashMap) SetIfAbsent(key string, value interface{}) bool { |
| 118 | // Get map shard. |
| 119 | shard := m.GetShard(key) |
| 120 | shard.Lock() |
| 121 | _, ok := shard.items[key] |
| 122 | if !ok { |
| 123 | shard.items[key] = value |
| 124 | } |
| 125 | shard.Unlock() |
| 126 | return !ok |
| 127 | } |
| 128 | |
| 129 | // Retrieves an element from map under given key. |
| 130 | func (m ConcurrentHashMap) Get(key string) (interface{}, bool) { |