MCPcopy Create free account
hub / github.com/Super-long/ChubbyGo / SetIfAbsent

Method SetIfAbsent

BaseServer/concurrentHashMap.go:117–127  ·  view source on GitHub ↗

Sets the given value under the specified key if no value was associated with it.

(key string, value interface{})

Source from the content-addressed store, hash-verified

115
116// Sets the given value under the specified key if no value was associated with it.
117func (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.
130func (m ConcurrentHashMap) Get(key string) (interface{}, bool) {

Callers

nothing calls this directly

Calls 1

GetShardMethod · 0.95

Tested by

no test coverage detected