Source File
stream.go
Belonging Package
github.com/beorn7/perks/quantile
package quantile
import (
)
:= targetMapToSlice()
:= func( *stream, float64) float64 {
var = math.MaxFloat64
var float64
for , := range {
if .quantile*.n <= {
= (2 * .epsilon * ) / .quantile
} else {
= (2 * .epsilon * (.n - )) / (1 - .quantile)
}
if < {
=
}
}
return
}
return newStream()
}
type target struct {
quantile float64
epsilon float64
}
func ( map[float64]float64) []target {
:= make([]target, 0, len())
for , := range {
:= target{
quantile: ,
epsilon: ,
}
= append(, )
}
return
}
func ( *Stream) () int {
return len(.b) + .stream.count()
}
func ( *Stream) () {
.maybeSort()
.stream.merge(.b)
.b = .b[:0]
}
func ( *Stream) () {
if !.sorted {
.sorted = true
sort.Sort(.b)
}
}
func ( *Stream) () bool {
return len(.stream.l) > 0
}
type stream struct {
n float64
l []Sample
ƒ invariant
}
func ( *stream) () {
.l = .l[:0]
.n = 0
}
func ( *stream) ( float64) {
.merge(Samples{{, 1, 0}})
}
}
++
goto
}
+= .Width
}
.l = append(.l, Sample{.Value, .Width, 0})
++
:
.n += .Width
+= .Width
}
.compress()
}
func ( *stream) () int {
return int(.n)
}
func ( *stream) ( float64) float64 {
:= math.Ceil( * .n)
+= math.Ceil(.ƒ(, ) / 2)
:= .l[0]
var float64
for , := range .l[1:] {
+= .Width
if +.Width+.Delta > {
return .Value
}
=
}
return .Value
}
func ( *stream) () {
if len(.l) < 2 {
return
}
:= .l[len(.l)-1]
:= len(.l) - 1
:= .n - 1 - .Width
for := len(.l) - 2; >= 0; -- {
:= .l[]
if .Width+.Width+.Delta <= .ƒ(, ) {
.Width += .Width
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |