Skip to content

Commit

Permalink
[ddsketch] Add getter for DDSketch zeroCount
Browse files Browse the repository at this point in the history
The zeroCount field of a DDSketch can currently be indirectly accessed
using:
s.GetCount() - s.GetPositiveValueStore().TotalCount() - s.GetNegativeValueStore().TotalCount()
but this is cumbersome to use (and causes additional computations).

This change makes the zeroCount directly accessible through the GetZeroCount() getter.
  • Loading branch information
KSerrania committed Mar 21, 2022
1 parent 276ddff commit b747a4f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ddsketch/ddsketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type quantileSketch interface {
RelativeAccuracy() float64
IsEmpty() bool
GetCount() float64
GetZeroCount() float64
GetSum() float64
GetPositiveValueStore() store.Store
GetNegativeValueStore() store.Store
Expand Down Expand Up @@ -202,6 +203,13 @@ func (s *DDSketch) GetCount() float64 {
return s.zeroCount + s.positiveValueStore.TotalCount() + s.negativeValueStore.TotalCount()
}

// GetZeroCount returns the number of zero values that have been added to this sketch.
// Note: values that are very small (lower than MinIndexableValue if positive, or higher than -MinIndexableValue if negative)
// are also mapped to the zero bucket.
func (s *DDSketch) GetZeroCount() float64 {
return s.zeroCount
}

// Return true iff no value has been added to this sketch.
func (s *DDSketch) IsEmpty() bool {
return s.zeroCount == 0 && s.positiveValueStore.IsEmpty() && s.negativeValueStore.IsEmpty()
Expand Down Expand Up @@ -538,6 +546,13 @@ func (s *DDSketchWithExactSummaryStatistics) GetCount() float64 {
return s.summaryStatistics.Count()
}

// GetZeroCount returns the number of zero values that have been added to this sketch.
// Note: values that are very small (lower than MinIndexableValue if positive, or higher than -MinIndexableValue if negative)
// are also mapped to the zero bucket.
func (s *DDSketchWithExactSummaryStatistics) GetZeroCount() float64 {
return s.DDSketch.zeroCount
}

func (s *DDSketchWithExactSummaryStatistics) GetSum() float64 {
return s.summaryStatistics.Sum()
}
Expand Down

0 comments on commit b747a4f

Please sign in to comment.