Add histogram Merge function
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -174,3 +175,21 @@ func (h *Histogram) findBucket(value int64) (int, error) {
|
|||||||
}
|
}
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Histogram) Merge(h2 *Histogram) {
|
||||||
|
if len(h.Buckets) != len(h2.Buckets) {
|
||||||
|
log.Fatalf("failed to merge histograms, inequivalent buckets length")
|
||||||
|
}
|
||||||
|
h.Count += h2.Count
|
||||||
|
h.Sum += h2.Sum
|
||||||
|
h.SumOfSquares += h2.SumOfSquares
|
||||||
|
if h2.Min < h.Min {
|
||||||
|
h.Min = h2.Min
|
||||||
|
}
|
||||||
|
if h2.Max > h.Max {
|
||||||
|
h.Max = h2.Max
|
||||||
|
}
|
||||||
|
for i, b := range h2.Buckets {
|
||||||
|
h.Buckets[i].Count += b.Count
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user