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