type Map … func (*Map[K, V]) less(l, r any) bool { … } func (m *Map[K, V]) String() string { … } type mapNode … type refValue … func newNodeWithRef[K constraints.Ordered, V any](key K, value V, release func(key, value any)) *mapNode { … } func (node *mapNode) shallowCloneWithRef() *mapNode { … } func (node *mapNode) incref() *mapNode { … } func (node *mapNode) decref() { … } // Clone returns a copy of the given map. It is a responsibility of the caller // to Destroy it at later time. func (pm *Map[K, V]) Clone() *Map[K, V] { … } // Destroy destroys the map. // // After Destroy, the Map should not be used again. func (pm *Map[K, V]) Destroy() { … } // Clear removes all entries from the map. func (pm *Map[K, V]) Clear() { … } // Keys returns all keys present in the map. func (pm *Map[K, V]) Keys() []K { … } // Range calls f sequentially in ascending key order for all entries in the map. func (pm *Map[K, V]) Range(f func(key K, value V)) { … } func (node *mapNode) forEach(f func(key, value any)) { … } // Get returns the map value associated with the specified key. // The ok result indicates whether an entry was found in the map. func (pm *Map[K, V]) Get(key K) (V, bool) { … } // SetAll updates the map with key/value pairs from the other map, overwriting existing keys. // It is equivalent to calling Set for each entry in the other map but is more efficient. func (pm *Map[K, V]) SetAll(other *Map[K, V]) { … } // Set updates the value associated with the specified key. // If release is non-nil, it will be called with entry's key and value once the // key is no longer contained in the map or any clone. func (pm *Map[K, V]) Set(key K, value V, release func(key, value any)) { … } // union returns a new tree which is a union of first and second one. // If overwrite is set to true, second one would override a value for any duplicate keys. // // union(first:-0, second:-0) (result:+1) // Union borrows both subtrees without affecting their refcount and returns a // new reference that the caller is expected to call decref. func union(first, second *mapNode, less func(any, any) bool, overwrite bool) *mapNode { … } // split the tree midway by the key into three different ones. // Return three new trees: left with all nodes with smaller than key, mid with // the node matching the key, right with all nodes larger than key. // If there are no nodes in one of trees, return nil instead of it. // If requireMid is set (such as during deletion), then all return arguments // are nil if mid is not found. // // split(n:-0) (left:+1, mid:+1, right:+1) // Split borrows n without affecting its refcount, and returns three // new references that the caller is expected to call decref. func split(n *mapNode, key any, less func(any, any) bool, requireMid bool) (left, mid, right *mapNode) { … } // Delete deletes the value for a key. // // The result reports whether the key was present in the map. func (pm *Map[K, V]) Delete(key K) bool { … } // merge two trees while preserving the weight invariant. // All nodes in left must have smaller keys than any node in right. // // merge(left:-0, right:-0) (result:+1) // Merge borrows its arguments without affecting their refcount // and returns a new reference that the caller is expected to call decref. func merge(left, right *mapNode) *mapNode { … }