Skip to content

Commit b3d9f3f

Browse files
committed
Flag isEmpty to be enum
1 parent 5b5f7ac commit b3d9f3f

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/main/java/org/apache/datasketches/count/CountMinSketch.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.apache.datasketches.hash.MurmurHash3;
2525
import org.apache.datasketches.tuple.Util;
2626

27-
import java.nio.Buffer;
2827
import java.nio.ByteBuffer;
2928
import java.nio.charset.StandardCharsets;
3029
import java.util.Random;
@@ -38,7 +37,14 @@ public class CountMinSketch {
3837
private final long[] sketchArray_;
3938
private long totalWeight_;
4039

41-
private static final int IS_EMPTY = 0;
40+
41+
private enum Flag {
42+
IS_EMPTY;
43+
44+
int mask() {
45+
return 1 << ordinal();
46+
}
47+
}
4248

4349
/**
4450
* Creates a CountMin sketch with given number of hash functions and buckets,
@@ -342,7 +348,7 @@ public void serialize(ByteBuffer buf) {
342348
buf.put((byte) serialVersion);
343349
final int familyId = Family.COUNTMIN.getID();
344350
buf.put((byte) familyId);
345-
final int flagsByte = isEmpty() ? 1 << IS_EMPTY : 0;
351+
final int flagsByte = isEmpty() ? Flag.IS_EMPTY.mask() : 0;
346352
buf.put((byte)flagsByte);
347353
final int NULL_32 = 0;
348354
buf.putInt(NULL_32);
@@ -391,7 +397,7 @@ public static CountMinSketch deserialize(final byte[] b, final long seed) {
391397
}
392398

393399
CountMinSketch cms = new CountMinSketch(numHashes, numBuckets, seed);
394-
final boolean empty = (flagsByte & (1 << IS_EMPTY)) > 0;
400+
final boolean empty = (flagsByte & Flag.IS_EMPTY.mask()) > 0;
395401
if (empty) {
396402
return cms;
397403
}

0 commit comments

Comments
 (0)