mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-09 04:17:51 +00:00
refactor mergeGroupCounts function
This commit is contained in:
parent
71ad297450
commit
0ab3e72520
1 changed files with 4 additions and 11 deletions
15
executor.go
15
executor.go
|
|
@ -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])
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue