Documentation
¶
Index ¶
- func All[K cmp.Ordered, V any](m Map[K, V]) iter.Seq2[K, V]
- func Copy[K cmp.Ordered, V any](dst *Map[K, V], src Map[K, V])
- func DeleteFunc[K cmp.Ordered, V any](m *Map[K, V], del func(K, V) bool)
- func Equal[K cmp.Ordered, V comparable](m1, m2 Map[K, V]) bool
- func EqualFunc[K cmp.Ordered, V1, V2 any](m1 Map[K, V1], m2 Map[K, V2], eq func(V1, V2) bool) bool
- func Insert[K cmp.Ordered, V any](m *Map[K, V], seq iter.Seq2[K, V])
- func Keys[K cmp.Ordered, V any](m Map[K, V]) iter.Seq[K]
- func Values[K cmp.Ordered, V any](m Map[K, V]) iter.Seq[V]
- type Color
- type KeyValue
- type Map
- type Node
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteFunc ¶
DeleteFunc deletes the key-value pairs that satisfy del.
func Equal ¶
func Equal[K cmp.Ordered, V comparable](m1, m2 Map[K, V]) bool
Equal returns if two maps contains the same key-value pairs.
func EqualFunc ¶
EqualFunc returns if two maps contains the same keys and their associated values satisfy eq.
Types ¶
type Map ¶
Map is a map backed by a binary search tree.
func (*Map[K, V]) Delete ¶
func (m *Map[K, V]) Delete(key K)
Delete removes the key-value pair from the map.
Example ¶
var m Map[string, int]
m.Set("a", 1)
m.Set("b", 2)
m.Set("c", 3)
snapshot := m
m.Delete("b")
for k, v := range All(m) {
fmt.Printf("%s: %v\n", k, v)
}
fmt.Println("rollback to snapshot")
m = snapshot
for k, v := range All(m) {
fmt.Printf("%s: %v\n", k, v)
}
Output: a: 1 c: 3 rollback to snapshot a: 1 b: 2 c: 3
func (*Map[K, V]) Set ¶
func (m *Map[K, V]) Set(key K, value V)
Set stores a pair of key and value.
Example ¶
var m Map[string, int]
m.Set("a", 1)
m.Set("b", 2)
snapshot := m
m.Set("c", 3)
m.Set("a", 4)
for k, v := range All(m) {
fmt.Printf("%s: %v\n", k, v)
}
fmt.Println("rollback to snapshot")
m = snapshot
for k, v := range All(m) {
fmt.Printf("%s: %v\n", k, v)
}
Output: a: 4 b: 2 c: 3 rollback to snapshot a: 1 b: 2
Click to show internal directories.
Click to hide internal directories.