143
// PutOrDo put the key value in the map, if key does not exists, otherwise, call fn with existing key and value
144
// return (value, fn evaluated or not, error when evaluation fn)
145
>
func (cmap *ShardedConcurrentTxMap) PutOrDo(key any, value any, fn ActionFunc) (any, bool, error) {
concurrent_tx_map.go
146
>
shard := cmap.getShard(key)
147
>
var err error
148
>
shard.Lock()
149
>
cmap.lazyInitShard(shard)
150
>
v, ok := shard.items[key]
151
>
if !ok {
152
>
shard.items[key] = value
153
>
v = value
154
>
atomic.AddInt32(&cmap.size, 1)
155
>
} else {
156
err = fn(key, v)
157
}
159
>
return v, ok, err
160
}
161