...
Source file
src/maps/maps.go
Documentation: maps
1
2
3
4
5
6 package maps
7
8
9
10 func Equal[M1, M2 ~map[K]V, K, V comparable](m1 M1, m2 M2) bool {
11 if len(m1) != len(m2) {
12 return false
13 }
14 for k, v1 := range m1 {
15 if v2, ok := m2[k]; !ok || v1 != v2 {
16 return false
17 }
18 }
19 return true
20 }
21
22
23
24 func EqualFunc[M1 ~map[K]V1, M2 ~map[K]V2, K comparable, V1, V2 any](m1 M1, m2 M2, eq func(V1, V2) bool) bool {
25 if len(m1) != len(m2) {
26 return false
27 }
28 for k, v1 := range m1 {
29 if v2, ok := m2[k]; !ok || !eq(v1, v2) {
30 return false
31 }
32 }
33 return true
34 }
35
36
37 func clone(m any) any
38
39
40
41 func Clone[M ~map[K]V, K comparable, V any](m M) M {
42
43 if m == nil {
44 return nil
45 }
46 return clone(m).(M)
47 }
48
49
50
51
52
53 func Copy[M1 ~map[K]V, M2 ~map[K]V, K comparable, V any](dst M1, src M2) {
54 for k, v := range src {
55 dst[k] = v
56 }
57 }
58
59
60 func DeleteFunc[M ~map[K]V, K comparable, V any](m M, del func(K, V) bool) {
61 for k, v := range m {
62 if del(k, v) {
63 delete(m, k)
64 }
65 }
66 }
67
View as plain text