github.com/clucia/cmap


License
Other
Install
go get github.com/clucia/cmap

Documentation

Cmap is a concurrent map implementation.

Cmap allows a group of goroutines to manipulate a map without collision. It serializes access to the go-map using the github.com/clucia/choke library and serves as an example of its use.

To initialize a cmap:

cm := New(0)
go cm.Start(ctx)

You can then use:

cm.Add(key, val)
cm.Update(key, val)
cm.CompareUpdate(key, val, compVal)
cm.Delete(key)
cm.Get(key)
cm.Range(cb func(key Key, val Val) error) - Iterate over the map calling callback func for each entry

CompareUpdate allows you to do a read-modify-write and guarantee atomicity.