refactor mergeGroupCounts function

This commit is contained in:
Travis Turner 2018-09-18 14:09:52 -05:00
parent 71ad297450
commit 0ab3e72520
No known key found for this signature in database
GPG key ID: 7F08008DFD9314C9

View file

@ -834,20 +834,13 @@ type GroupCount struct {
}
func mergeGroupCounts(gc, other []GroupCount) []GroupCount {
m := make(map[string]struct {
i int
count uint64
})
m := make(map[string]int)
for i := range gc {
m[uniqueGroupString(gc[i].Group)] = struct {
i int
count uint64
}{i, gc[i].Count}
m[uniqueGroupString(gc[i].Group)] = i
}
for i := range other {
o, found := m[uniqueGroupString(other[i].Group)]
if found {
gc[o.i].Count += other[i].Count
if idx, found := m[uniqueGroupString(other[i].Group)]; found {
gc[idx].Count += other[i].Count
} else {
gc = append(gc, other[i])
}