Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Add Count() #14

Merged
merged 1 commit into from
Dec 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func TestHistogram(t *testing.T) {
for _, val := range testData {
h.Add(float64(val))
}
if h.total != 14999 {
t.Errorf("Expected h.total to be 100, got ", h.total)
if h.Count() != 14999 {
t.Errorf("Expected h.Count() to be 100, got ", h.Count())
}

if firstQ := h.Quantile(0.25); !approx(firstQ, 14) {
Expand Down
4 changes: 4 additions & 0 deletions numerichistogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func (h *NumericHistogram) Variance() float64 {
return sum / float64(h.total)
}

func (h *NumericHistogram) Count() float64 {
return float64(h.total)
}

// trim merges adjacent bins to decrease the bin count to the maximum value
func (h *NumericHistogram) trim() {
for len(h.bins) > h.maxbins {
Expand Down
4 changes: 4 additions & 0 deletions weightedhistogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ func (h *WeightedHistogram) Variance() float64 {
return sum / h.total
}

func (h *WeightedHistogram) Count() float64 {
return h.total
}

func (h *WeightedHistogram) trim() {
total := 0.0
for i := range h.bins {
Expand Down