You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by le...@apache.org on 2025/07/29 04:25:54 UTC
(datasketches-java) branch fix_minor_issues_with_count_min created (now c6a5154b8)
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a change to branch fix_minor_issues_with_count_min
in repository https://gitbox.apache.org/repos/asf/datasketches-java.git
at c6a5154b8 fix minor issues with count min
This branch includes the following new commits:
new 9187165ed Fixed conflict
new 6fd3cd992 Merge branch 'main' of git@github.com:apache/datasketches-java.git into main
new c6a5154b8 fix minor issues with count min
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org
(datasketches-java) 03/03: fix minor issues with count min
Posted by le...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch fix_minor_issues_with_count_min
in repository https://gitbox.apache.org/repos/asf/datasketches-java.git
commit c6a5154b8c95f07b23160cb57ca0e900f8b5b3ea
Author: Lee Rhodes <le...@gmail.com>
AuthorDate: Mon Jul 28 21:25:38 2025 -0700
fix minor issues with count min
---
.../apache/datasketches/count/CountMinSketch.java | 44 ++++++++++------------
1 file changed, 20 insertions(+), 24 deletions(-)
diff --git a/src/main/java/org/apache/datasketches/count/CountMinSketch.java b/src/main/java/org/apache/datasketches/count/CountMinSketch.java
index eb9fb1ce8..9bf576e13 100644
--- a/src/main/java/org/apache/datasketches/count/CountMinSketch.java
+++ b/src/main/java/org/apache/datasketches/count/CountMinSketch.java
@@ -19,6 +19,13 @@
package org.apache.datasketches.count;
+import static java.lang.foreign.ValueLayout.JAVA_BYTE;
+import static java.lang.foreign.ValueLayout.JAVA_LONG_UNALIGNED;
+
+import java.lang.foreign.MemorySegment;
+import java.nio.charset.StandardCharsets;
+import java.util.Random;
+
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.common.SketchesException;
@@ -26,16 +33,6 @@ import org.apache.datasketches.common.Util;
import org.apache.datasketches.common.positional.PositionalSegment;
import org.apache.datasketches.hash.MurmurHash3;
-import java.lang.foreign.MemorySegment;
-import java.nio.charset.StandardCharsets;
-import java.util.Random;
-
-import static java.lang.foreign.ValueLayout.JAVA_BYTE;
-import static java.lang.foreign.ValueLayout.JAVA_INT_UNALIGNED;
-import static java.lang.foreign.ValueLayout.JAVA_LONG_UNALIGNED;
-import static java.lang.foreign.ValueLayout.JAVA_SHORT_UNALIGNED;
-
-
/**
* Java implementation of the CountMin sketch data structure of Cormode and Muthukrishnan.
* This implementation is inspired by and compatible with the datasketches-cpp version by Charlie Dickens.
@@ -85,8 +82,8 @@ public class CountMinSketch {
throw new SketchesArgumentException("Number of buckets must be positive, got: " + numBuckets);
}
if (numBuckets < 3) {
- 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));
+ 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));
}
// Check for potential overflow in array size calculation
@@ -101,7 +98,7 @@ public class CountMinSketch {
// be 2^31-1. We check only against 2^30 for simplicity.
if (totalSize >= (1L << 30)) {
throw new SketchesArgumentException("Sketch would require excessive memory: " + numHashes + " * " + numBuckets
- + " = " + totalSize + " elements (~" + String.format("%d", totalSize * Long.BYTES / (1024 * 1024 * 1024)) + " GB). "
+ + " = " + totalSize + " elements (~" + String.format("%d", (totalSize * Long.BYTES) / (1024 * 1024 * 1024)) + " GB). "
+ "Consider reducing numHashes or numBuckets.");
}
@@ -127,13 +124,12 @@ public class CountMinSketch {
return segment.toArray(JAVA_BYTE);
}
-
private long[] getHashes(final byte[] item) {
final long[] updateLocations = new long[numHashes_];
for (int i = 0; i < numHashes_; i++) {
final long[] index = MurmurHash3.hash(item, hashSeeds_[i]);
- updateLocations[i] = i * (long)numBuckets_ + Math.floorMod(index[0], numBuckets_);
+ updateLocations[i] = (i * (long)numBuckets_) + Math.floorMod(index[0], numBuckets_);
}
return updateLocations;
@@ -184,7 +180,7 @@ public class CountMinSketch {
* @return The relative error.
*/
public double getRelativeError() {
- return Math.exp(1.0) / (double)numBuckets_;
+ return Math.exp(1.0) / numBuckets_;
}
/**
@@ -193,7 +189,7 @@ public class CountMinSketch {
* @return Suggested number of hash functions.
*/
public static byte suggestNumHashes(final double confidence) {
- if (confidence < 0 || confidence > 1) {
+ if ((confidence < 0) || (confidence > 1)) {
throw new SketchesException("Confidence must be between 0 and 1.0 (inclusive).");
}
final int value = (int) Math.ceil(Math.log(1.0 / (1.0 - confidence)));
@@ -227,7 +223,7 @@ public class CountMinSketch {
* @param weight The weight of the item.
*/
public void update(final String item, final long weight) {
- if (item == null || item.isEmpty()) {
+ if ((item == null) || item.isEmpty()) {
return;
}
final byte[] strByte = item.getBytes(StandardCharsets.UTF_8);
@@ -266,7 +262,7 @@ public class CountMinSketch {
* @return Estimated frequency.
*/
public long getEstimate(final String item) {
- if (item == null || item.isEmpty()) {
+ if ((item == null) || item.isEmpty()) {
return 0;
}
@@ -309,7 +305,7 @@ public class CountMinSketch {
* @return Upper bound of estimated frequency.
*/
public long getUpperBound(final String item) {
- if (item == null || item.isEmpty()) {
+ if ((item == null) || item.isEmpty()) {
return 0;
}
@@ -345,7 +341,7 @@ public class CountMinSketch {
* @return Lower bound of estimated frequency.
*/
public long getLowerBound(final String item) {
- if (item == null || item.isEmpty()) {
+ if ((item == null) || item.isEmpty()) {
return 0;
}
@@ -371,8 +367,8 @@ public class CountMinSketch {
throw new SketchesException("Cannot merge a sketch with itself");
}
- final boolean acceptableConfig = getNumBuckets_() == other.getNumBuckets_()
- && getNumHashes_() == other.getNumHashes_() && getSeed_() == other.getSeed_();
+ final boolean acceptableConfig = (getNumBuckets_() == other.getNumBuckets_())
+ && (getNumHashes_() == other.getNumHashes_()) && (getSeed_() == other.getSeed_());
if (!acceptableConfig) {
throw new SketchesException("Incompatible sketch configuration.");
@@ -396,9 +392,9 @@ public class CountMinSketch {
return preambleBytes + Long.BYTES + (sketchArray_.length * Long.BYTES);
}
-
/**
* Returns the sketch as a byte array.
+ * @return the result byte array
*/
public byte[] toByteArray() {
final int serializedSizeBytes = getSerializedSizeBytes();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org
(datasketches-java) 01/03: Fixed conflict
Posted by le...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch fix_minor_issues_with_count_min
in repository https://gitbox.apache.org/repos/asf/datasketches-java.git
commit 9187165ed8d5a62cf14e8d6384f12d5752ed534f
Author: Lee Rhodes <le...@gmail.com>
AuthorDate: Mon Jul 28 21:17:46 2025 -0700
Fixed conflict
---
.../java/org/apache/datasketches/cpc/CpcSketchCrossLanguageTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/java/org/apache/datasketches/cpc/CpcSketchCrossLanguageTest.java b/src/test/java/org/apache/datasketches/cpc/CpcSketchCrossLanguageTest.java
index 16cc55db9..906f1a52a 100644
--- a/src/test/java/org/apache/datasketches/cpc/CpcSketchCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/cpc/CpcSketchCrossLanguageTest.java
@@ -89,7 +89,7 @@ public class CpcSketchCrossLanguageTest {
int flavorIdx = 0;
for (int n: nArr) {
final byte[] bytes = Files.readAllBytes(goPath.resolve("cpc_n" + n + "_go.sk"));
- final CpcSketch sketch = CpcSketch.heapify(Memory.wrap(bytes));
+ final CpcSketch sketch = CpcSketch.heapify(MemorySegment.ofArray(bytes));
assertEquals(sketch.getFlavor(), flavorArr[flavorIdx++]);
assertEquals(sketch.getEstimate(), n, n * 0.02);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org
(datasketches-java) 02/03: Merge branch 'main' of git@github.com:apache/datasketches-java.git into main
Posted by le...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch fix_minor_issues_with_count_min
in repository https://gitbox.apache.org/repos/asf/datasketches-java.git
commit 6fd3cd992152d28ca5195494febd5503f90e2914
Merge: 9187165ed 9d1f24f5a
Author: Lee Rhodes <le...@gmail.com>
AuthorDate: Mon Jul 28 21:18:51 2025 -0700
Merge branch 'main' of git@github.com:apache/datasketches-java.git into main
.../apache/datasketches/count/CountMinSketch.java | 224 ++++++++++++++-------
.../datasketches/count/CountMinSketchTest.java | 12 +-
2 files changed, 154 insertions(+), 82 deletions(-)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org