concurrent-map icon indicating copy to clipboard operation
concurrent-map copied to clipboard

How to make Nested maps with concurrent Map?

Open nishitm opened this issue 7 years ago • 2 comments

For example, In regular map

var data = map[string]map[string]string{}

data["a"] = map[string]string{}
data["b"] = make(map[string]string)
data["c"] = make(map[string]string)

data["a"]["w"] = "x"
data["b"]["w"] = "x"
data["c"]["w"] = "x"

How to do this kind of nested map using concurrent Map? Any Idea

nishitm avatar Jul 18 '18 09:07 nishitm

You need to do type assertion with ConcurrentMap type to the nested concurrent map:

var data = cmap.New()
if v, ok := data.Get("key"); !ok {
  data.Set("nested_key", cmap.New())
} else {
  nested := v.(cmap.ConcurrentMap)
  nested.Set("key", "value")
}

cookiebody avatar Aug 01 '18 01:08 cookiebody

Has anyone done benchmarking with nested cmaps?

yunginnanet avatar Mar 10 '22 08:03 yunginnanet