File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ type Map interface {
30
30
// Delete removes the key from the map.
31
31
Delete (key string )
32
32
// Equals compares the two maps, and return true if they are the same, false otherwise.
33
+ // Implementations can use MapEquals as a general implementation for this methods.
33
34
Equals (other Map ) bool
34
35
// Iterate runs the given function for each key/value in the
35
36
// map. Returning false in the closure prematurely stops the
@@ -87,3 +88,24 @@ func MapCompare(lhs, rhs Map) int {
87
88
i ++
88
89
}
89
90
}
91
+
92
+ // MapEquals returns true if lhs == rhs, false otherwise. This function
93
+ // acts on generic types and should not be used by callers, but can help
94
+ // implement Map.Equals.
95
+ func MapEquals (lhs , rhs Map ) bool {
96
+ if lhs .Length () != rhs .Length () {
97
+ return false
98
+ }
99
+ return lhs .Iterate (func (k string , v Value ) bool {
100
+ vo , ok := rhs .Get (k )
101
+ if ! ok {
102
+ return false
103
+ }
104
+ if ! Equals (v , vo ) {
105
+ vo .Recycle ()
106
+ return false
107
+ }
108
+ vo .Recycle ()
109
+ return true
110
+ })
111
+ }
You can’t perform that action at this time.
0 commit comments