leerho commented on code in PR #676:
URL: https://github.com/apache/datasketches-java/pull/676#discussion_r2229748283
##########
src/main/java/org/apache/datasketches/count/CountMinSketch.java:
##########
@@ -57,30 +65,59 @@ int mask() {
* @param seed The base hash seed
*/
CountMinSketch(final byte numHashes, final int numBuckets, final long seed) {
- numHashes_ = numHashes;
- numBuckets_ = numBuckets;
- seed_ = seed;
- hashSeeds_ = new long[numHashes];
- sketchArray_ = new long[numHashes * numBuckets];
- totalWeight_ = 0;
+ // Validate numHashes
+ if (numHashes <= 0) {
+ throw new SketchesArgumentException("Number of hash functions must be
positive, got: " + numHashes);
+ }
+ // Validate numBuckets with clear mathematical justification
+ if (numBuckets <= 0) {
+ throw new SketchesArgumentException("Number of buckets must be positive,
got: " + numBuckets);
+ }
if (numBuckets < 3) {
- throw new SketchesArgumentException("Using fewer than 3 buckets incurs
relative error greater than 1.");
+ throw new SketchesArgumentException("Number of buckets must be at least
3 to ensure relative error ≤ 1.0. " +
+ "With " + numBuckets + " buckets, relative error would be " +
String.format("%.3f", Math.exp(1.0) / numBuckets));
Review Comment:
The "+" should be at the beginning of the next line.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]