Avoid divide-by-zero in CardinalityCounter::Size

This commit is contained in:
Tim Wojtulewicz 2025-04-04 15:42:41 -07:00
parent bde2dec685
commit bf82f8afc1
2 changed files with 6 additions and 1 deletions

View file

@ -134,6 +134,10 @@ void CardinalityCounter::AddElement(uint64_t hash) {
**/
double CardinalityCounter::Size() const {
double answer = 0;
if ( m == 0 )
return -1.0;
for ( unsigned int i = 0; i < m; i++ )
answer += pow(2, -((int)buckets[i]));

View file

@ -75,7 +75,8 @@ public:
* Get the current estimated number of elements in the data
* structure
*
* @return Estimated number of elements
* @return Estimated number of elements. Returns -1.0 if there are
* zero buckets.
**/
double Size() const;