func Elems(m Map) map[uint64]interface{}
Elems are the (k,v) elements in the Map as a map[uint64]interface{}
func TakeLhs(lhs, rhs interface{}) interface{}
TakeLhs always returns the left value in a collision.
func TakeRhs(lhs, rhs interface{}) interface{}
TakeRhs always returns the right hand side in a collision.
Builder creates new Map. Each Builder has a unique Scope.
IMPORTANT: Nodes are hash-consed internally to reduce memory consumption. To support hash-consing Builders keep an internal Map of all of the Maps that they have created. To GC any of the Maps created by the Builder, all references to the Builder must be dropped. This includes MutMaps.
type Builder struct {
// contains filtered or unexported fields
}
func NewBuilder() *Builder
NewBuilder creates a new Builder with a unique Scope.
func (b *Builder) Clone(m Map) Map
Clone returns a Map that contains the same (key, value) elements within b.Scope(), i.e. return m if m.Scope() == b.Scope() or return a deep copy of m within b.Scope() otherwise.
func (b *Builder) Create(m map[uint64]interface{}) Map
func (b *Builder) Empty() Map
Empty is the empty map.
func (b *Builder) Insert(m Map, k uint64, v interface{}) Map
Inserts a new association from key to value into the Map m to create a new map in the current scope.
If there was a previous value mapped by key, keep the previously mapped value. This is roughly corresponds to updating a map[uint64]interface{} by:
if _, ok := m[k]; ok { m[k] = val }
This is equivalent to b.Merge(m, b.Create({k: v})).
func (b *Builder) InsertWith(c Collision, m Map, k uint64, v interface{}) Map
InsertWith inserts a new association from k to v into the Map m to create a new map in the current scope and handle collisions using the collision function c.
This is roughly corresponds to updating a map[uint64]interface{} by:
if _, ok := m[k]; ok { m[k] = c(m[k], v} else { m[k] = v}
An insertion or update happened whenever Insert(m, ...) != m .
func (b *Builder) Intersect(lhs, rhs Map) Map
Intersect Maps lhs and rhs and returns a map with all of the keys in both lhs and rhs and the value comes from lhs, i.e.
{(k, lhs[k]) | k in lhs, k in rhs}.
func (b *Builder) IntersectWith(c Collision, lhs, rhs Map) Map
IntersectWith take lhs and rhs and returns the intersection with the value coming from the collision function, i.e.
{(k, c(lhs[k], rhs[k]) ) | k in lhs, k in rhs}.
The elements of the resulting map are always { <k, c(lhs[k], rhs[k]) > } for each key k that a key in both lhs and rhs.
func (b *Builder) Merge(lhs, rhs Map) Map
Merge two maps lhs and rhs to create a new map in the current scope.
Whenever there is a key in both maps (a collision), the resulting value mapped by the key will be the value in lhs `b.Collision(lhs[key], rhs[key])`.
func (b *Builder) MergeWith(c Collision, lhs, rhs Map) Map
Merge two maps lhs and rhs to create a new map in the current scope.
Whenever there is a key in both maps (a collision), the resulting value mapped by the key will be `c(lhs[key], rhs[key])`.
func (b *Builder) MutEmpty() MutMap
MutEmpty is an empty MutMap for a builder.
func (b *Builder) Remove(m Map, k uint64) Map
Remove a key from a Map m and return the resulting Map.
func (b *Builder) Rescope()
Rescope changes the builder's scope to a new unique Scope.
Any Maps created using the previous scope need to be Cloned before any operation.
This makes the old internals of the Builder eligible to be GC'ed.
func (b *Builder) Scope() Scope
func (b *Builder) Update(m Map, key uint64, val interface{}) Map
Updates a (key, value) in the map. This is roughly corresponds to updating a map[uint64]interface{} by:
m[key] = val
Collision functions combine a left and right hand side (lhs and rhs) values the two values are associated with the same key and produces the value that will be stored for the key.
Collision functions must be idempotent:
collision(x, x) == x for all x.
Collisions functions may be applied whenever a value is inserted or two maps are merged, or intersected.
type Collision func(lhs interface{}, rhs interface{}) interface{}
Map is effectively a finite mapping from uint64 keys to interface{} values. Maps are immutable and can be read from concurrently.
Notes on concurrency:
type Map struct {
// contains filtered or unexported fields
}
func (m Map) DeepEqual(other Map) bool
DeepEqual returns true if m and other contain the same (k, v) mappings [regardless of Scope].
Equivalently m.DeepEqual(other) <=> reflect.DeepEqual(Elems(m), Elems(other))
func (m Map) Lookup(k uint64) (interface{}, bool)
func (m Map) Range(cb func(uint64, interface{}) bool) bool
Range over the leaf (key, value) pairs in the map in order and applies cb(key, value) to each. Stops early if cb returns false. Returns true if all elements were visited without stopping early.
func (m Map) Scope() Scope
func (m Map) Size() int
func (m Map) String() string
Converts the map into a {<key>: <value>[, ...]} string. This uses the default %s string conversion for <value>.
MutMap is a convenient wrapper for a Map and a *Builder that will be used to create new Maps from it.
type MutMap struct { B *Builder M Map }
func (mm *MutMap) Insert(k uint64, v interface{}) bool
Insert an element into the map using the collision function for the builder. Returns true if the element was inserted.
func (mm *MutMap) Intersect(other Map) bool
Intersect another map into the current one using the collision function for the builder. Returns true if the map changed.
func (mm *MutMap) Merge(other Map) bool
Merge another map into the current one using the collision function for the builder. Returns true if the map changed.
func (mm *MutMap) MergeWith(c Collision, other Map) bool
Merge another map into the current one using the collision function for the builder. Returns true if the map changed.
func (mm *MutMap) Remove(k uint64) bool
Removes a key from the map. Returns true if the element was removed.
func (mm *MutMap) Update(k uint64, v interface{}) bool
Updates an element in the map. Returns true if the map was updated.
Scope represents a distinct collection of maps. Maps with the same Scope can be equal. Maps in different scopes are distinct. Each Builder creates maps within a unique Scope.
type Scope struct {
// contains filtered or unexported fields
}
func (s Scope) String() string