ZBLOG

golang Map LoadOrStore

func (m Map) LoadOrStore(key, value interface{}) (actual interface{}, loaded bool)

The function LoadOrStore is a method of the Map type in Golang. It takes two parameters, key and value, and returns two values: actual and loaded.

  • key: The key to be looked up or inserted into the map.
  • value: The value to be stored in the map if the key is not already present.

If the given key is already present in the map, then LoadOrStore returns the corresponding value and the boolean value ‘true’ to indicate that the value was loaded from the map. If the given key is not present in the map, then it stores the given key-value pair in the map and returns the newly inserted value and the boolean value ‘false’ to indicate that the value was stored in the map.

The LoadOrStore method can be used to implement concurrency-safe maps using the sync.Map type in Go.

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=356

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?