concurrent-map
concurrent-map copied to clipboard
How to make Nested maps with concurrent Map?
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
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")
}
Has anyone done benchmarking with nested cmaps?