Skip to content

Commit

Permalink
Mutation growth fixes (#2)
Browse files Browse the repository at this point in the history
* stabilise mutation sorting

* fix growth sum when multi-threading
  • Loading branch information
richardgoater authored Jul 20, 2022
1 parent 9f7905e commit 3d6d016
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions covince/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,25 @@ func min(a, b int) int {

type SortByCount []*MutationSearch

func (s SortByCount) Less(i, j int) bool { return s[i].Count < s[j].Count }
func (s SortByCount) Len() int { return len(s) }
func (s SortByCount) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s SortByCount) Less(i, j int) bool {
if s[i].Count == s[j].Count {
return SortByName(s).Less(i, j)
}
return s[i].Count < s[j].Count
}
func (s SortByCount) Len() int { return len(s) }
func (s SortByCount) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

type SortByGrowth []*MutationSearch

func (s SortByGrowth) Less(i, j int) bool { return s[i].Growth < s[j].Growth }
func (s SortByGrowth) Len() int { return len(s) }
func (s SortByGrowth) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s SortByGrowth) Less(i, j int) bool {
if s[i].Growth == s[j].Growth {
return SortByName(s).Less(i, j)
}
return s[i].Growth < s[j].Growth
}
func (s SortByGrowth) Len() int { return len(s) }
func (s SortByGrowth) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

type SortByName []*MutationSearch

Expand Down Expand Up @@ -82,6 +92,8 @@ func SearchMutations(foreach IteratorFunc, q *Query, opts *SearchOpts) SearchRes
for k, v := range results[i] {
if sr, ok := m[k]; ok {
sr.Count += v.Count
sr.growthStart += v.growthStart
sr.growthEnd += v.growthEnd
} else {
m[k] = v
}
Expand Down

0 comments on commit 3d6d016

Please sign in to comment.