// NewHistogram implements Provider.
773305
func (p expvarProvider) NewHistogram(name string, buckets int) metrics.Histogram {
	return expvar.NewHistogram(name, buckets)
}
1097236
func histogram(b []byte, h []int32) {
	h = h[:256]
	for _, t := range b {
		h[t]++
	}
}
1280630
func NewHistogramDiffer(a, b []string) *HistogramDiffer {
	return &HistogramDiffer{a: a, b: b}
}
1023621
func NewHDRHistogram(low, high int64, sigfigs int) (h *HDRHistogram, err error) {
	defer func() {
		if msg := recover(); msg != nil {
			err = fmt.Errorf("%s", msg)
		}
	}()
	return &HDRHistogram{
		low:     low,
		high:    high,
		sigfigs: sigfigs,
		h:       hdrhistogram.New(low, high, sigfigs),
	}, nil
}
646679
func NewHistogram(opts prometheus.HistogramOpts) prometheus.Histogram {
	h := prometheus.NewHistogram(opts)
	prometheus.MustRegister(h)
	return h
}
1177282
func NewRollingHDRHistogram(low, high int64, sigfigs int, period time.Duration, bucketCount int, options ...rhOptSetter) (*RollingHDRHistogram, error) {
	rh := &RollingHDRHistogram{
		bucketCount: bucketCount,
		period:      period,
		low:         low,
		high:        high,
		sigfigs:     sigfigs,
	}

	for _, o := range options {
		if err := o(rh); err != nil {
			return nil, err
		}
	}

	if rh.clock == nil {
		rh.clock = &timetools.RealTime{}
	}

	buckets := make([]*HDRHistogram, rh.bucketCount)
	for i := range buckets {
		h, err := NewHDRHistogram(low, high, sigfigs)
		if err != nil {
			return nil, err
		}
		buckets[i] = h
	}
	rh.buckets = buckets
	return rh, nil
}
678355
func (m *RTMetrics) LatencyHistogram() (*HDRHistogram, error) {
	m.histogramLock.Lock()
	defer m.histogramLock.Unlock()
	return m.histogram.Merged()
}
610368
func (h *Histogram) Add(value int64) error {
	bucket, err := h.findBucket(value)
	if err != nil {
		return err
	}
	h.Buckets[bucket].Count++
	h.Count++
	h.Sum += value
	h.SumOfSquares += value * value
	if value < h.Min {
		h.Min = value
	}
	if value > h.Max {
		h.Max = value
	}
	return nil
}
111895
func (t *Timings) Histograms() (h map[string]*Histogram) {
	t.mu.Lock()
	defer t.mu.Unlock()
	h = make(map[string]*Histogram, len(t.histograms))
	for k, v := range t.histograms {
		h[k] = v
	}
	return
}
537052
func PowerHist(power float64, input []float64) Histogram {
	if len(input) == 0 || power <= 0 {
		return Histogram{}
	}

	minx, maxx := input[0], input[0]
	for _, val := range input {
		minx = math.Min(minx, val)
		maxx = math.Max(maxx, val)
	}

	fromPower := math.Floor(logbase(minx, power))
	toPower := math.Floor(logbase(maxx, power))

	buckets := make([]Bucket, int(toPower-fromPower)+1)
	for i, bkt := range buckets {
		bkt.Min = math.Pow(power, float64(i)+fromPower)
		bkt.Max = math.Pow(power, float64(i+1)+fromPower)
		buckets[i] = bkt
	}

	minC := 0
	maxC := 0
	for _, val := range input {
		powAway := logbase(val, power) - fromPower
		bi := int(math.Floor(powAway))
		buckets[bi].Count++
		minC = imin(buckets[bi].Count, minC)
		maxC = imax(buckets[bi].Count, maxC)
	}

	return Histogram{
		Min:     minC,
		Max:     maxC,
		Count:   len(input),
		Buckets: buckets,
	}
}
113559
func New() *Histogram {
	return &Histogram{
		allocd:   defaultHistSize,
		used:     0,
		bvs:      make([]bin, defaultHistSize),
		useLocks: true,
	}
}
332156
func NewGetHistogramArgs(name string) *GetHistogramArgs {
	args := new(GetHistogramArgs)
	args.Name = name
	return args
}
207418
func NewHistoCounter(sink *Counter) *HistoCounter {
	return &HistoCounter{
		sink:            sink,
		DatapointBucket: sfxclient.NewRollingBucket("datapoint_batch_size", map[string]string{}),
		EventBucket:     sfxclient.NewRollingBucket("event_batch_size", map[string]string{}),
		SpanBucket:      sfxclient.NewRollingBucket("span_batch_size", map[string]string{}),
	}
}
1218938
func (c *Client) Histogram(name string, value int) error {
	return c.send(name, 1, "%d|ms", value)
}
13588
func (h *Histogram) UnmarshalJSON(b []byte) error {
	var s string
	if err := json.Unmarshal(b, &s); err != nil {
		return err
	}
	data, err := base64.StdEncoding.DecodeString(s)
	if err != nil {
		return err
	}
	h, err = Deserialize(bytes.NewBuffer(data))
	return err
}
482881
func (a Aggregations) KeyedDateHistogram(name string) (*AggregationBucketKeyedHistogramItems, bool) {
	if raw, found := a[name]; found {
		agg := new(AggregationBucketKeyedHistogramItems)
		if raw == nil {
			return agg, true
		}
		if err := json.Unmarshal(raw, agg); err == nil {
			return agg, true
		}
	}
	return nil, false
}
384940
func UpdateHistogram(h *Histogram, feedback *QueryFeedback) *Histogram {
	buckets, isNewBuckets, totalCount := splitBuckets(h, feedback)
	buckets = mergeBuckets(buckets, isNewBuckets, float64(totalCount))
	hist := buildNewHistogram(h, buckets)
	// Update the NDV of primary key column.
	if feedback.Tp == PkType {
		hist.NDV = int64(hist.TotalRowCount())
	}
	return hist
}