mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-15 19:41:02 +00:00
use mapEqual where possible
This commit is contained in:
@@ -115,25 +115,7 @@ func (c Counters) String() string {
|
||||
|
||||
// DeepEqual tests equality with other Counters
|
||||
func (c Counters) DeepEqual(d Counters) bool {
|
||||
if (c.psMap == nil) != (d.psMap == nil) {
|
||||
return false
|
||||
} else if c.psMap == nil && d.psMap == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
if c.psMap.Size() != d.psMap.Size() {
|
||||
return false
|
||||
}
|
||||
|
||||
equal := true
|
||||
c.psMap.ForEach(func(k string, val interface{}) {
|
||||
if otherValue, ok := d.psMap.Lookup(k); !ok {
|
||||
equal = false
|
||||
} else {
|
||||
equal = equal && reflect.DeepEqual(val, otherValue)
|
||||
}
|
||||
})
|
||||
return equal
|
||||
return mapEqual(c.psMap, d.psMap, reflect.DeepEqual)
|
||||
}
|
||||
|
||||
func (c Counters) fromIntermediate(in map[string]int) Counters {
|
||||
|
||||
@@ -129,22 +129,7 @@ func (c EdgeMetadatas) String() string {
|
||||
|
||||
// DeepEqual tests equality with other Counters
|
||||
func (c EdgeMetadatas) DeepEqual(d EdgeMetadatas) bool {
|
||||
if c.Size() != d.Size() {
|
||||
return false
|
||||
}
|
||||
if c.Size() == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
equal := true
|
||||
c.psMap.ForEach(func(k string, val interface{}) {
|
||||
if otherValue, ok := d.psMap.Lookup(k); !ok {
|
||||
equal = false
|
||||
} else {
|
||||
equal = equal && reflect.DeepEqual(val, otherValue)
|
||||
}
|
||||
})
|
||||
return equal
|
||||
return mapEqual(c.psMap, d.psMap, reflect.DeepEqual)
|
||||
}
|
||||
|
||||
// CodecEncodeSelf implements codec.Selfer
|
||||
|
||||
@@ -142,28 +142,8 @@ func (n NodeSet) String() string {
|
||||
}
|
||||
|
||||
// DeepEqual tests equality with other NodeSets
|
||||
func (n NodeSet) DeepEqual(i interface{}) bool {
|
||||
d, ok := i.(NodeSet)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
if n.Size() != d.Size() {
|
||||
return false
|
||||
}
|
||||
if n.Size() == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
equal := true
|
||||
n.psMap.ForEach(func(k string, val interface{}) {
|
||||
if otherValue, ok := d.psMap.Lookup(k); !ok {
|
||||
equal = false
|
||||
} else {
|
||||
equal = equal && reflect.DeepEqual(val, otherValue)
|
||||
}
|
||||
})
|
||||
return equal
|
||||
func (n NodeSet) DeepEqual(o NodeSet) bool {
|
||||
return mapEqual(n.psMap, o.psMap, reflect.DeepEqual)
|
||||
}
|
||||
|
||||
func (n NodeSet) toIntermediate() []Node {
|
||||
|
||||
@@ -129,22 +129,7 @@ func (s Sets) String() string {
|
||||
|
||||
// DeepEqual tests equality with other Sets
|
||||
func (s Sets) DeepEqual(t Sets) bool {
|
||||
if s.Size() != t.Size() {
|
||||
return false
|
||||
}
|
||||
if s.Size() == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
equal := true
|
||||
s.psMap.ForEach(func(k string, val interface{}) {
|
||||
if otherValue, ok := t.psMap.Lookup(k); !ok {
|
||||
equal = false
|
||||
} else {
|
||||
equal = equal && reflect.DeepEqual(val, otherValue)
|
||||
}
|
||||
})
|
||||
return equal
|
||||
return mapEqual(s.psMap, t.psMap, reflect.DeepEqual)
|
||||
}
|
||||
|
||||
// CodecEncodeSelf implements codec.Selfer
|
||||
|
||||
Reference in New Issue
Block a user