use mapEqual where possible

This commit is contained in:
Matthias Radestock
2017-05-29 12:26:39 +01:00
parent b703f4d9bd
commit f09be95a43
4 changed files with 5 additions and 73 deletions

View File

@@ -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 {

View File

@@ -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

View File

@@ -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 {

View File

@@ -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