This library provides:
-
A lockless Golang map implementing the Context interface. (ContextMapper)
-
An immutable multi-versioned map built on top of the lockless map, similarly implementing the Context interface. (ImmutMapper)
a) Add
b) Exists
c) Delete
d) Iterate
type IterMap struct {
key, value interface{}
}
type ContextMapper interface {
Exists(interface{}) (interface{}, bool)
Add(interface{}, interface{}) interface{}
Delete(interface{})
Iterate() <-chan IterMap
}
As can be seen from above, it implements an interface similar to that of regular map.
type IntfMap map[interface{}]interface{}
type ImutMapper interface {
Exists(interface{}) (interface{}, bool, IntfMap)
Add(interface{}, interface{}) IntfMap
Delete(interface{})
}
ImmutMapper implements similar interface, except it returns a 3rd value
which is a snapshot
of the map into which the operation was done.
Both ContextMapper and ImmutMapper encapsulate context.Context:
type baseMap struct {
context.Context
// Other internal fields
}
and provide constructors such as:
NewcontextMapper(ctx context.Context) (ContextMapper, context.CancelFunc)
and
NewImutMapper(ctx context.Context) (ImutMapper, context.CancelFunc)
and finally,
type ContextImutMapper interface {
Exists(interface{}) (interface{}, bool, ContextMapper)
Add(interface{}, interface{}) ContextMapper
}
which combines both ContextMapper and ImmutMapper.
The key and values inserted can by of any type and heterogenous.
Please refer to godoc for more details.
- http://github.com/ronin13/dotler : Multiple crawler goroutines use ContextMapper to avoid duplicate crawling and for in-memory graph.