SHARE
TWEET

Untitled

a guest May 25th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "sync"
  6. )
  7.  
  8. var _ = sync.Map{}
  9.  
  10. func main() {
  11.     m := sync.Map{}
  12.     m.Store("demon", 1)
  13.     m.Store("huohuojun", 2)
  14.     m.Store("zhangqing", 3)
  15.  
  16.     m.Range(func(k, v interface{}) bool {
  17.         fmt.Printf("name: %s,index: %d\n", k, v)
  18.         return true
  19.     })
  20.  
  21.     // load or store
  22.     v, ok := m.LoadOrStore("zhangxi", 4)
  23.     if ok {
  24.         fmt.Println(v)
  25.         fmt.Print("lalala")
  26.     }
  27.  
  28.     m.Range(func(k, v interface{}) bool {
  29.         fmt.Printf("name: %s,index: %d\n", k, v)
  30.         return true
  31.     })
  32.  
  33.     m.Delete("demon")
  34.     m.Delete("huohuojun")
  35.  
  36.     m.Range(func(k, v interface{}) bool {
  37.         fmt.Printf("name: %s,index: %d\n", k, v)
  38.         return true
  39.     })
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top