From f09be95a4367bec53d6e654fbbb43856afe0b27f Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 29 May 2017 12:26:39 +0100 Subject: [PATCH] use mapEqual where possible --- report/counters.go | 20 +------------------- report/edge_metadatas.go | 17 +---------------- report/node_set.go | 24 ++---------------------- report/sets.go | 17 +---------------- 4 files changed, 5 insertions(+), 73 deletions(-) diff --git a/report/counters.go b/report/counters.go index e5b7bcf3f..a110330dd 100644 --- a/report/counters.go +++ b/report/counters.go @@ -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 { diff --git a/report/edge_metadatas.go b/report/edge_metadatas.go index 2927b6708..4d34e95a9 100644 --- a/report/edge_metadatas.go +++ b/report/edge_metadatas.go @@ -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 diff --git a/report/node_set.go b/report/node_set.go index 8c73c2099..b302488a2 100644 --- a/report/node_set.go +++ b/report/node_set.go @@ -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 { diff --git a/report/sets.go b/report/sets.go index be1c78b7c..183ada1de 100644 --- a/report/sets.go +++ b/report/sets.go @@ -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