Skip to content

Commit 47fc7ff

Browse files
authored
Allow to combine histograms
1 parent 960ec59 commit 47fc7ff

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

histogram.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,40 @@ func PutFast(f *Fast) {
129129
}
130130

131131
var fastPool sync.Pool
132+
133+
func Quantile(fs []*Fast, phi float64) float64 {
134+
return combine(fs).quantile(phi)
135+
}
136+
137+
func Quantiles(fs []*Fast, dst, phis []float64) []float64 {
138+
t := combine(fs)
139+
for _, phi := range phis {
140+
q := t.quantile(phi)
141+
dst = append(dst, q)
142+
}
143+
return dst
144+
}
145+
146+
func combine(fs []*Fast) Fast {
147+
n := 0
148+
for _, f := range fs {
149+
n += len(f.a)
150+
}
151+
152+
var t Fast
153+
t.Reset()
154+
t.tmp = make([]float64, 0, n)
155+
156+
for _, f := range fs {
157+
t.tmp = append(t.tmp, f.a...)
158+
if t.max < f.max {
159+
t.max = f.max
160+
}
161+
if t.min > f.min {
162+
t.min = f.min
163+
}
164+
}
165+
sort.Float64s(t.tmp)
166+
167+
return t
168+
}

0 commit comments

Comments
 (0)