diff --git a/README.md b/README.md index b270bde0..b0ae5f4a 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ However, this algorithm can be useful for file indexes, for example, to find ide ```java // create some file in the given path File file = path.resolve("test.txt").toFile(); -try (FileWriter fileWriter = new FileWriter(file)) { +try (FileWriter fileWriter = new FileWriter(file, StandardCharsets.UTF_8)) { fileWriter.write("this is the file content"); } diff --git a/build.gradle b/build.gradle index 13478e8a..5fa76391 100644 --- a/build.gradle +++ b/build.gradle @@ -20,6 +20,7 @@ plugins { id 'signing' id 'io.github.gradle-nexus.publish-plugin' version '1.3.0' id "com.palantir.revapi" version "1.7.0" + id "net.ltgt.errorprone" version "3.1.0" } static def readJavaLicense(licenseName) { @@ -185,6 +186,7 @@ dependencies { testImplementation group: 'net.openhft', name: 'zero-allocation-hashing', version: '0.16' testImplementation group: 'com.appmattus.crypto', name: 'cryptohash', version: '0.10.1' testImplementation group: 'org.greenrobot', name: 'essentials', version: '3.1.0' + errorprone("com.google.errorprone:error_prone_core:2.24.0") } jacocoTestReport { @@ -383,4 +385,10 @@ nexusPublishing { if (file("extra-configuration.gradle").exists()) { apply from: 'extra-configuration.gradle' -} \ No newline at end of file +} + +tasks.withType(JavaCompile).configureEach { + options.compilerArgs << "-Werror" + options.errorprone.disableWarningsInGeneratedCode = false + // options.errorprone.enabled = false +} diff --git a/src/jmh/java/com/dynatrace/hash4j/distinctcount/HyperLogLogPerformanceTest.java b/src/jmh/java/com/dynatrace/hash4j/distinctcount/HyperLogLogPerformanceTest.java index 4db98261..1e2c384e 100644 --- a/src/jmh/java/com/dynatrace/hash4j/distinctcount/HyperLogLogPerformanceTest.java +++ b/src/jmh/java/com/dynatrace/hash4j/distinctcount/HyperLogLogPerformanceTest.java @@ -71,6 +71,7 @@ public void distinctCountAddWithMartingaleEstimator(AddState addState, Blackhole blackhole.consume(martingaleEstimator.getDistinctCountEstimate()); } + @SuppressWarnings("ImmutableEnumChecker") public enum Estimator { MAXIMUM_LIKELIHOOD_ESTIMATOR(HyperLogLog.MAXIMUM_LIKELIHOOD_ESTIMATOR), CORRECTED_RAW_ESTIMATOR(HyperLogLog.CORRECTED_RAW_ESTIMATOR); diff --git a/src/jmh/java/com/dynatrace/hash4j/distinctcount/UltraLogLogPerformanceTest.java b/src/jmh/java/com/dynatrace/hash4j/distinctcount/UltraLogLogPerformanceTest.java index 66c1897e..2003b7e9 100644 --- a/src/jmh/java/com/dynatrace/hash4j/distinctcount/UltraLogLogPerformanceTest.java +++ b/src/jmh/java/com/dynatrace/hash4j/distinctcount/UltraLogLogPerformanceTest.java @@ -71,6 +71,7 @@ public void distinctCountAddWithMartingaleEstimator(AddState addState, Blackhole blackhole.consume(martingaleEstimator.getDistinctCountEstimate()); } + @SuppressWarnings("ImmutableEnumChecker") public enum Estimator { MAXIMUM_LIKELIHOOD_ESTIMATOR(UltraLogLog.MAXIMUM_LIKELIHOOD_ESTIMATOR), OPTIMAL_FGRA_ESTIMATOR(UltraLogLog.OPTIMAL_FGRA_ESTIMATOR); diff --git a/src/jmh/java/com/dynatrace/hash4j/hashing/AbstractPerformanceTest.java b/src/jmh/java/com/dynatrace/hash4j/hashing/AbstractPerformanceTest.java index 897265e4..12c2fa12 100644 --- a/src/jmh/java/com/dynatrace/hash4j/hashing/AbstractPerformanceTest.java +++ b/src/jmh/java/com/dynatrace/hash4j/hashing/AbstractPerformanceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Dynatrace LLC + * Copyright 2022-2023 Dynatrace LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -281,8 +281,7 @@ private static String createRandomString(int minLen, int maxLen, SplittableRando int len = random.nextInt(minLen, maxLen + 1); StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; ++i) { - char c = 'a'; - c += random.nextInt(0, 26); + char c = (char) ('a' + random.nextInt(0, 26)); sb.append(c); } return sb.toString(); @@ -292,9 +291,8 @@ private static String createRandomGreekString(int minLen, int maxLen, Splittable int len = random.nextInt(minLen, maxLen + 1); StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; ++i) { - char c = 0x03B1; - c += random.nextInt(0, 24); - if (c >= 0x03C2) c += 1; + char c = (char) (0x03B1 + random.nextInt(0, 24)); + if (c >= 0x03C2) c = (char) (c + 1); sb.append(c); } return sb.toString(); @@ -311,8 +309,6 @@ private static TestObject[] createTestObjects( } static { - final SplittableRandom random = new SplittableRandom(0); - BYTE_ARRAYS_1 = createRandomByteArrays(NUM_OBJECTS, 1, 1, 0x035348bcb49493a4L); BYTE_ARRAYS_4 = createRandomByteArrays(NUM_OBJECTS, 1, 4, 0xcc6444ca02edfbd0L); BYTE_ARRAYS_16 = createRandomByteArrays(NUM_OBJECTS, 1, 16, 0x187c616cabc3e0a7L); @@ -346,7 +342,7 @@ private static TestObject[] createTestObjects( TEST_OBJECTS1 = createTestObjects(NUM_OBJECTS, TestObject1::new, 0x37569b3107539e19L); TEST_OBJECTS2 = createTestObjects(NUM_OBJECTS, TestObject2::new, 0x892da841ae127839L); TEST_OBJECTS3 = createTestObjects(NUM_OBJECTS, TestObject3::new, 0xb443e2873a03f397L); - TEST_OBJECTS4 = createTestObjects(NUM_OBJECTS, TestObject3::new, 0x49952ea071f1cc0aL); + TEST_OBJECTS4 = createTestObjects(NUM_OBJECTS, TestObject4::new, 0x49952ea071f1cc0aL); } private void directBytesTest(byte[][] data, Blackhole blackhole) { diff --git a/src/jmh/java/com/dynatrace/hash4j/hashing/AbstractZeroAllocationHashing64BitPerformanceTest.java b/src/jmh/java/com/dynatrace/hash4j/hashing/AbstractZeroAllocationHashing64BitPerformanceTest.java index f74a22b3..3f6ee5ac 100644 --- a/src/jmh/java/com/dynatrace/hash4j/hashing/AbstractZeroAllocationHashing64BitPerformanceTest.java +++ b/src/jmh/java/com/dynatrace/hash4j/hashing/AbstractZeroAllocationHashing64BitPerformanceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Dynatrace LLC + * Copyright 2022-2023 Dynatrace LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,6 +45,7 @@ protected long hashCharsIndirect(String s) { protected abstract LongHashFunction createHashFunction(); + @Override protected long hashObject(TestObject testObject) { try { ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(); diff --git a/src/jmh/java/com/dynatrace/hash4j/hashing/UnorderedHashTest.java b/src/jmh/java/com/dynatrace/hash4j/hashing/UnorderedHashTest.java index c4383ac7..8dd8cf12 100644 --- a/src/jmh/java/com/dynatrace/hash4j/hashing/UnorderedHashTest.java +++ b/src/jmh/java/com/dynatrace/hash4j/hashing/UnorderedHashTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Dynatrace LLC + * Copyright 2022-2023 Dynatrace LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ import java.util.List; import java.util.SplittableRandom; import java.util.concurrent.ThreadLocalRandom; -import java.util.function.ToLongFunction; import java.util.stream.Collectors; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; @@ -40,10 +39,13 @@ public class UnorderedHashTest { } private static final HashFunnel LONG_FUNNEL = (l, h) -> h.putLong(l); - private static final ToLongFunction LONG_2_HASH = - x -> Hashing.murmur3_128().hashToLong(x, LONG_FUNNEL); + + private static final long long2Hash(long x) { + return Hashing.murmur3_128().hashToLong(x, LONG_FUNNEL); + } + private static final HashFunnel> LIST_LONG_FUNNEL = - (l, h) -> h.putUnorderedIterable(l, LONG_2_HASH); + (l, h) -> h.putUnorderedIterable(l, UnorderedHashTest::long2Hash); @Benchmark @BenchmarkMode(Mode.AverageTime) diff --git a/src/main/java/com/dynatrace/hash4j/distinctcount/HyperLogLog.java b/src/main/java/com/dynatrace/hash4j/distinctcount/HyperLogLog.java index cbfb9904..05a6e591 100644 --- a/src/main/java/com/dynatrace/hash4j/distinctcount/HyperLogLog.java +++ b/src/main/java/com/dynatrace/hash4j/distinctcount/HyperLogLog.java @@ -322,7 +322,7 @@ public static int computeToken(long hashValue) { */ @Override public HyperLogLog add(long hashValue, StateChangeObserver stateChangeObserver) { - int idx = (int) (hashValue >>> (-p)); + int idx = (int) (hashValue >>> -p); int newValue = Long.numberOfLeadingZeros(~(~hashValue << p)) + 1; int oldValue = (int) ARRAY_HANDLER.update(state, idx, newValue, Math::max); if (stateChangeObserver != null && newValue > oldValue) { @@ -601,7 +601,7 @@ private static final class MaximumLikelihoodEstimator implements Estimator { // // for a numerical evaluation see // https://www.wolframalpha.com/input?i=sqrt%28ln%282%29%2Fzeta%282%2C2%29%29 - private static final double INV_SQRT_FISHER_INFORMATION = 1.0367047097785011; + private static final double INV_SQRT_FISHER_INFORMATION = 1.0367047097785012; private static final double ML_EQUATION_SOLVER_EPS = 0.001 * INV_SQRT_FISHER_INFORMATION; // 0.1% of theoretical relative error diff --git a/src/main/java/com/dynatrace/hash4j/distinctcount/UltraLogLog.java b/src/main/java/com/dynatrace/hash4j/distinctcount/UltraLogLog.java index 2f8a6e16..8e5adce3 100644 --- a/src/main/java/com/dynatrace/hash4j/distinctcount/UltraLogLog.java +++ b/src/main/java/com/dynatrace/hash4j/distinctcount/UltraLogLog.java @@ -245,10 +245,10 @@ public static int computeToken(long hashValue) { public UltraLogLog add(long hashValue, StateChangeObserver stateChangeObserver) { int q = Long.numberOfLeadingZeros(state.length - 1L); // q = 64 - p int idx = (int) (hashValue >>> q); - int nlz = Long.numberOfLeadingZeros(~(~hashValue << (-q))); // nlz in {0, 1, ..., 64-p} + int nlz = Long.numberOfLeadingZeros(~(~hashValue << -q)); // nlz in {0, 1, ..., 64-p} byte oldState = state[idx]; long hashPrefix = unpack(oldState); - hashPrefix |= 1L << (nlz + (~q)); // (nlz + (~q)) = (nlz + p - 1) in {p-1, ... 63} + hashPrefix |= 1L << (nlz + ~q); // (nlz + (~q)) = (nlz + p - 1) in {p-1, ... 63} byte newState = pack(hashPrefix); state[idx] = newState; if (stateChangeObserver != null && newState != oldState) { @@ -323,7 +323,7 @@ static long unpack(byte register) { // visible for testing static byte pack(long hashPrefix) { int nlz = Long.numberOfLeadingZeros(hashPrefix) + 1; - return (byte) (((-nlz) << 2) | ((hashPrefix << nlz) >>> 62)); + return (byte) ((-nlz << 2) | ((hashPrefix << nlz) >>> 62)); } /** @@ -410,7 +410,7 @@ private static final class MaximumLikelihoodEstimator implements Estimator { // // for a numerical evaluation see // https://www.wolframalpha.com/input?i=3%2F2+*+ln%282%29+*+zeta%283%2C5%2F4%29%2F%28zeta%282%2C5%2F4%29%29%5E2 - private static final double ML_BIAS_CORRECTION_CONSTANT = 0.48147376527720066; + private static final double ML_BIAS_CORRECTION_CONSTANT = 0.48147376527720065; // returns contribution to alpha, scaled by 2^64 private static long contribute(int r, int[] b, int p) { @@ -772,7 +772,7 @@ static double smallRangeEstimate(long c0, long c4, long c8, long c10, long m) { long alpha = m + 3 * (c0 + c4 + c8 + c10); long beta = m - c0 - c4; long gamma = 4 * c0 + 2 * c4 + 3 * c8 + c10; - double quadRootZ = (sqrt(beta * beta + 4 * alpha * gamma) - beta) / (2 * alpha); + double quadRootZ = (sqrt((double) (beta * beta + 4 * alpha * gamma)) - beta) / (2 * alpha); double rootZ = quadRootZ * quadRootZ; return rootZ * rootZ; } @@ -781,7 +781,7 @@ static double largeRangeEstimate(long c4w0, long c4w1, long c4w2, long c4w3, lon long alpha = m + 3 * (c4w0 + c4w1 + c4w2 + c4w3); long beta = c4w0 + c4w1 + 2 * (c4w2 + c4w3); long gamma = m + 2 * c4w0 + c4w2 - c4w3; - return sqrt((sqrt(beta * beta + 4 * alpha * gamma) - beta) / (2 * alpha)); + return sqrt((sqrt((double) (beta * beta + 4 * alpha * gamma)) - beta) / (2 * alpha)); } // this is psi as defined in the paper divided by ETA_X diff --git a/src/main/java/com/dynatrace/hash4j/hashing/AbstractHashStream.java b/src/main/java/com/dynatrace/hash4j/hashing/AbstractHashStream.java index 269873c1..ca2ef153 100644 --- a/src/main/java/com/dynatrace/hash4j/hashing/AbstractHashStream.java +++ b/src/main/java/com/dynatrace/hash4j/hashing/AbstractHashStream.java @@ -159,7 +159,7 @@ public HashStream putInts(int[] x, int off, int len) { @Override public HashStream putLong(long v) { - putInt((int) (v)); + putInt((int) v); putInt((int) (v >> 32)); return this; } diff --git a/src/main/java/com/dynatrace/hash4j/hashing/AbstractKomihash.java b/src/main/java/com/dynatrace/hash4j/hashing/AbstractKomihash.java index edf53829..97ffaa07 100644 --- a/src/main/java/com/dynatrace/hash4j/hashing/AbstractKomihash.java +++ b/src/main/java/com/dynatrace/hash4j/hashing/AbstractKomihash.java @@ -257,7 +257,7 @@ public HashStream64 putChars(CharSequence s) { remainingChars -= 32; off += 32; } while (remainingChars >= 32); - buffer[0] = (byte) (z); + buffer[0] = (byte) z; } } } diff --git a/src/main/java/com/dynatrace/hash4j/hashing/AbstractWyhashFinal.java b/src/main/java/com/dynatrace/hash4j/hashing/AbstractWyhashFinal.java index 6bd8b4cf..d63e3e39 100644 --- a/src/main/java/com/dynatrace/hash4j/hashing/AbstractWyhashFinal.java +++ b/src/main/java/com/dynatrace/hash4j/hashing/AbstractWyhashFinal.java @@ -222,7 +222,7 @@ protected static long[] makeSecret(long seed) { ok = true; seed += 0xa0761d6478bd642fL; secret[i] = - (c[(int) (Long.remainderUnsigned(wymix(seed, seed ^ 0xe7037ed1a0b428dbL), c.length))] + (c[(int) Long.remainderUnsigned(wymix(seed, seed ^ 0xe7037ed1a0b428dbL), c.length)] & 0xFFL); if ((secret[i] & 1) == 0) { seed += 0x633acdbf4d2dbd49L; // = 7 * 0xa0761d6478bd642fL @@ -232,7 +232,7 @@ protected static long[] makeSecret(long seed) { for (int j = 8; j < 64; j += 8) { seed += 0xa0761d6478bd642fL; secret[i] |= - (c[(int) (Long.remainderUnsigned(wymix(seed, seed ^ 0xe7037ed1a0b428dbL), c.length))] + (c[(int) Long.remainderUnsigned(wymix(seed, seed ^ 0xe7037ed1a0b428dbL), c.length)] & 0xFFL) << j; } @@ -438,7 +438,7 @@ public HashStream64 putChars(CharSequence s) { setLong(buffer, 32, b4); setLong(buffer, 40, b5); } - buffer[0] = (byte) (z); + buffer[0] = (byte) z; } } while (remainingChars >= 4) { diff --git a/src/main/java/com/dynatrace/hash4j/hashing/FarmHashNa.java b/src/main/java/com/dynatrace/hash4j/hashing/FarmHashNa.java index 3260611d..b3291f0c 100644 --- a/src/main/java/com/dynatrace/hash4j/hashing/FarmHashNa.java +++ b/src/main/java/com/dynatrace/hash4j/hashing/FarmHashNa.java @@ -66,10 +66,9 @@ class FarmHashNa extends AbstractHasher64 { private static final long K1 = 0xb492b66fbe98f273L; protected static final long K2 = 0x9ae16a3b2f90404fL; private static final long K_MUL = 0x9ddfea08eb382d69L; - private static final long SEED = 81; - private static final long START_X = SEED * K2; - private static final long START_Y = SEED * K1 + 113; - private static final long START_Z = shiftMix(START_Y * K2 + 113) * K2; + private static final long START_X = 0x1529cba0ca458ffL; + private static final long START_Y = 0x226bb95b4e64b6d4L; + private static final long START_Z = 0x134a747f856d0526L; private static final FarmHashNa INSTANCE = new FarmHashNa(); @@ -733,6 +732,7 @@ private long naHashLen33To64(int bufferCount) { rotateRight(e + f, 43) + rotateRight(g, 30) + h, e + rotateRight(f + a, 18) + g, mul); } + @Override public long getAsLong() { return finalizeHash(processRemaining()); } diff --git a/src/main/java/com/dynatrace/hash4j/hashing/HashStream128.java b/src/main/java/com/dynatrace/hash4j/hashing/HashStream128.java index 919b51a3..c6efbbe4 100644 --- a/src/main/java/com/dynatrace/hash4j/hashing/HashStream128.java +++ b/src/main/java/com/dynatrace/hash4j/hashing/HashStream128.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Dynatrace LLC + * Copyright 2022-2023 Dynatrace LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -171,5 +171,6 @@ HashStream128 putUnorderedIterable( * * @return this */ + @Override HashStream128 reset(); } diff --git a/src/main/java/com/dynatrace/hash4j/hashing/HashStream64.java b/src/main/java/com/dynatrace/hash4j/hashing/HashStream64.java index f2957705..d54f4bf8 100644 --- a/src/main/java/com/dynatrace/hash4j/hashing/HashStream64.java +++ b/src/main/java/com/dynatrace/hash4j/hashing/HashStream64.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Dynatrace LLC + * Copyright 2022-2023 Dynatrace LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -171,5 +171,6 @@ HashStream64 putUnorderedIterable( * * @return this */ + @Override HashStream64 reset(); } diff --git a/src/main/java/com/dynatrace/hash4j/hashing/Komihash4_3.java b/src/main/java/com/dynatrace/hash4j/hashing/Komihash4_3.java index 4f81a899..a19fe451 100644 --- a/src/main/java/com/dynatrace/hash4j/hashing/Komihash4_3.java +++ b/src/main/java/com/dynatrace/hash4j/hashing/Komihash4_3.java @@ -152,7 +152,7 @@ public long hashBytesToLong(byte[] input, int off, int len) { } else if (len > 3) { long fb = getInt(input, off) & 0xFFFFFFFFL; long y = getInt(input, off + len - 4); - fb |= (y << 32) >>> (-ml8); + fb |= (y << 32) >>> -ml8; fb |= 1L << ml8 << (y >>> 63); r2l ^= fb; } else if (len > 0) { @@ -267,7 +267,7 @@ public long hashCharsToLong(CharSequence input) { } else if (len > 1) { long fb = getInt(input, off) & 0xFFFFFFFFL; long y = getInt(input, off + len - 2); - fb |= (y << 32) >>> (-ml8); + fb |= (y << 32) >>> -ml8; fb |= 1L << ml8 << (y >>> 63); r2l ^= fb; } else if (len > 0) { diff --git a/src/main/java/com/dynatrace/hash4j/hashing/Komihash5_0.java b/src/main/java/com/dynatrace/hash4j/hashing/Komihash5_0.java index 7d39ebf6..02dddb2f 100644 --- a/src/main/java/com/dynatrace/hash4j/hashing/Komihash5_0.java +++ b/src/main/java/com/dynatrace/hash4j/hashing/Komihash5_0.java @@ -146,11 +146,11 @@ public long hashBytesToLong(byte[] input, int off, int len) { if (len > 7) { r2l ^= getLong(input, off); long y = getLong(input, off + len - 8); - r2h ^= (1L << ml8) | (y >>> 1 >>> (~ml8)); + r2h ^= (1L << ml8) | (y >>> 1 >>> ~ml8); } else if (len > 3) { long mh = getInt(input, off + len - 4); long ml = getInt(input, off) & 0xFFFFFFFFL; - r2l ^= (1L << ml8) | ml | (mh << 32 >>> (-ml8)); + r2l ^= (1L << ml8) | ml | (mh << 32 >>> -ml8); } else if (len > 0) { long m = (1L << ml8) | (input[off] & 0xFFL); if (len > 1) m |= (input[off + 1] & 0xFFL) << 8; @@ -256,11 +256,11 @@ public long hashCharsToLong(CharSequence input) { if (len > 3) { r2l ^= getLong(input, off); long y = getLong(input, off + len - 4); - r2h ^= (1L << ml8) | (y >>> 1 >>> (~ml8)); + r2h ^= (1L << ml8) | (y >>> 1 >>> ~ml8); } else if (len > 1) { long mh = getInt(input, off + len - 2); long ml = getInt(input, off) & 0xFFFFFFFFL; - r2l ^= (1L << ml8) | ml | (mh << 32 >>> (-ml8)); + r2l ^= (1L << ml8) | ml | (mh << 32 >>> -ml8); } else if (len > 0) { long m = (1L << ml8) | input.charAt(off); r2l ^= m; diff --git a/src/main/java/com/dynatrace/hash4j/hashing/Murmur3_128.java b/src/main/java/com/dynatrace/hash4j/hashing/Murmur3_128.java index c3aa16a0..340b0a26 100644 --- a/src/main/java/com/dynatrace/hash4j/hashing/Murmur3_128.java +++ b/src/main/java/com/dynatrace/hash4j/hashing/Murmur3_128.java @@ -264,7 +264,7 @@ public HashStream128 putShort(short v) { processBuffer(buffer0, buffer1); } buffer0 = buffer1; - buffer1 = (l >>> (-bitCount)); + buffer1 = (l >>> -bitCount); } bitCount += 16; return this; @@ -279,7 +279,7 @@ public HashStream128 putInt(int v) { processBuffer(buffer0, buffer1); } buffer0 = buffer1; - buffer1 = (l >>> (-bitCount)); + buffer1 = (l >>> -bitCount); } bitCount += 32; return this; @@ -292,7 +292,7 @@ public HashStream128 putLong(long l) { processBuffer(buffer0, buffer1); } buffer0 = buffer1; - buffer1 = (l >>> 1 >>> (~bitCount)); + buffer1 = (l >>> 1 >>> ~bitCount); bitCount += 64; return this; } @@ -302,12 +302,12 @@ public HashStream128 putBytes(byte[] b, int off, int len) { final long oldBitCount = bitCount; final int numWrittenBytes = (int) bitCount >>> 3; - final int regularBlockStartIdx = (-numWrittenBytes) & 0xF; + final int regularBlockStartIdx = -numWrittenBytes & 0xF; final int regularBlockEndIdx = len - ((len + numWrittenBytes) & 0xF); bitCount += ((long) len) << 3; if (regularBlockEndIdx < regularBlockStartIdx) { - int z = (-numWrittenBytes) & 0x7; + int z = -numWrittenBytes & 0x7; if (len < z) { for (int x = 0; x < len; ++x) { buffer1 |= (b[off + x] & 0xFFL) << ((x + numWrittenBytes) << 3); @@ -330,11 +330,11 @@ public HashStream128 putBytes(byte[] b, int off, int len) { if (regularBlockStartIdx > 0) { if (regularBlockStartIdx >= 8) { if (regularBlockStartIdx > 8) { - buffer0 = buffer1 | (getLong(b, off)) << oldBitCount; + buffer0 = buffer1 | getLong(b, off) << oldBitCount; } buffer1 = getLong(b, off + regularBlockStartIdx - 8); } else if (len >= 8) { - buffer1 |= (getLong(b, off)) << oldBitCount; + buffer1 |= getLong(b, off) << oldBitCount; } else { if (regularBlockStartIdx >= 4) { if (regularBlockStartIdx >= 5) { @@ -372,11 +372,11 @@ public HashStream128 putBytes(byte[] b, int off, int len) { if (0 < remainingBytes) { if (8 <= remainingBytes) { if (8 < remainingBytes) { - buffer1 = (getLong(b, offLen - 8)) >>> (-(remainingBytes << 3)); + buffer1 = getLong(b, offLen - 8) >>> -(remainingBytes << 3); } buffer0 = getLong(b, offLen - remainingBytes); } else if (len >= 8) { - buffer1 |= (getLong(b, offLen - 8)) >>> (-(remainingBytes << 3)); + buffer1 |= getLong(b, offLen - 8) >>> -(remainingBytes << 3); } else { if (3 < remainingBytes) { buffer1 |= (((long) getInt(b, offLen - remainingBytes)) & 0xFFFFFFFFL); @@ -448,14 +448,14 @@ public long getAsLong() { @Override public HashStream128 putChars(CharSequence s) { final int len = s.length(); - int i = ((8 - (int) (bitCount)) >>> 4) & 0x7; + int i = ((8 - (int) bitCount) >>> 4) & 0x7; if (len < i) { for (int j = 0; j < len; j++) { final long l = s.charAt(j); buffer1 |= l << bitCount; if ((bitCount & 0x30L) == 0x30L) { buffer0 = buffer1; - buffer1 = (l >>> (-bitCount)); + buffer1 = l >>> -bitCount; } bitCount += 16; } diff --git a/src/main/java/com/dynatrace/hash4j/hashing/Murmur3_32.java b/src/main/java/com/dynatrace/hash4j/hashing/Murmur3_32.java index 21689c8e..7d2b017a 100644 --- a/src/main/java/com/dynatrace/hash4j/hashing/Murmur3_32.java +++ b/src/main/java/com/dynatrace/hash4j/hashing/Murmur3_32.java @@ -181,7 +181,7 @@ public HashStream32 putLong(long l) { @Override public HashStream32 putBytes(byte[] b, int off, int len) { - final int regularBlockStartIdx = (-length) & 0x3; + final int regularBlockStartIdx = -length & 0x3; final int regularBlockEndIdx = len - ((len + length) & 0x3); length += len; if (regularBlockEndIdx < regularBlockStartIdx) { @@ -229,7 +229,7 @@ public HashStream32 putBytes(byte[] b, int off, int len) { @Override public int getAsInt() { - return fmix32(h1 ^ mixK1((int) (buffer)) ^ length); + return fmix32(h1 ^ mixK1((int) buffer) ^ length); } private void processBuffer(int x) { diff --git a/src/main/java/com/dynatrace/hash4j/hashing/PolymurHash2_0.java b/src/main/java/com/dynatrace/hash4j/hashing/PolymurHash2_0.java index 98a438fe..3eb6af98 100644 --- a/src/main/java/com/dynatrace/hash4j/hashing/PolymurHash2_0.java +++ b/src/main/java/com/dynatrace/hash4j/hashing/PolymurHash2_0.java @@ -397,7 +397,7 @@ private long polymurLoadLeU64_0_8(CharSequence input, long off, long len) { } } } - return r >>> (-(len << 3)); + return r >>> -(len << 3); } private static long getLong7(CharSequence input, long off) { @@ -768,7 +768,7 @@ private long finish() { } long m0 = k; if (offset > 0) { - m0 += getLong(buffer, 0) & (0xFFFFFFFFFFFFFFFFL >>> (-(offset << 3))); + m0 += getLong(buffer, 0) & (0xFFFFFFFFFFFFFFFFL >>> -(offset << 3)); } long lenk2 = offset + k2; return polyAcc + polymurRed611(unsignedMultiplyHigh(m0, lenk2), m0 * lenk2); diff --git a/src/main/java/com/dynatrace/hash4j/random/RandomExponentialUtil.java b/src/main/java/com/dynatrace/hash4j/random/RandomExponentialUtil.java index 80754ae6..16a18b15 100644 --- a/src/main/java/com/dynatrace/hash4j/random/RandomExponentialUtil.java +++ b/src/main/java/com/dynatrace/hash4j/random/RandomExponentialUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Dynatrace LLC + * Copyright 2022-2023 Dynatrace LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,524 +64,524 @@ final class RandomExponentialUtil { private RandomExponentialUtil() {} - private static final double[] X = { - 8.6971174701310497140, - 7.6971174701310497140, - 6.9410336293772123602, - 6.4783784938325698538, - 6.1441646657724730491, - 5.8821443157953997963, - 5.6664101674540337371, - 5.4828906275260628694, - 5.3230905057543986131, - 5.1814872813015010392, - 5.0542884899813047117, - 4.9387770859012514838, - 4.8329397410251125881, - 4.7352429966017412526, - 4.6444918854200854873, - 4.5597370617073515513, - 4.4802117465284221949, - 4.4052876934735729805, - 4.3344436803172730116, - 4.2672424802773661873, - 4.2033137137351843802, - 4.1423408656640511251, - 4.0840513104082974638, - 4.0282085446479365106, - 3.9746060666737884793, - 3.9230625001354895926, - 3.8734176703995089983, - 3.8255294185223367372, - 3.7792709924116678992, - 3.7345288940397975350, - 3.6912010902374189454, - 3.6491955157608538478, - 3.6084288131289096339, - 3.5688252656483374051, - 3.5303158891293438633, - 3.4928376547740601814, - 3.4563328211327607625, - 3.4207483572511205323, - 3.3860354424603017887, - 3.3521490309001100106, - 3.3190474709707487166, - 3.2866921715990692095, - 3.2550473085704501813, - 3.2240795652862645207, - 3.1937579032122407483, - 3.1640533580259734580, - 3.1349388580844407393, - 3.1063890623398246660, - 3.0783802152540905188, - 3.0508900166154554479, - 3.0238975044556767713, - 2.9973829495161306949, - 2.9713277599210896472, - 2.9457143948950456386, - 2.9205262865127406647, - 2.8957477686001416838, - 2.8713640120155362592, - 2.8473609656351888266, - 2.8237253024500354905, - 2.8004443702507381944, - 2.7775061464397572041, - 2.7548991965623453650, - 2.7326126361947007411, - 2.7106360958679293686, - 2.6889596887418041593, - 2.6675739807732670816, - 2.6464699631518093905, - 2.6256390267977886123, - 2.6050729387408355373, - 2.5847638202141406911, - 2.5647041263169053687, - 2.5448866271118700928, - 2.5253043900378279427, - 2.5059507635285939648, - 2.4868193617402096807, - 2.4679040502973649846, - 2.4491989329782498908, - 2.4306983392644199088, - 2.4123968126888708336, - 2.3942890999214583288, - 2.3763701405361408194, - 2.3586350574093374601, - 2.3410791477030346875, - 2.3236978743901964559, - 2.3064868582835798692, - 2.2894418705322694265, - 2.2725588255531546952, - 2.2558337743672190441, - 2.2392628983129087111, - 2.2228425031110364013, - 2.2065690132576635755, - 2.1904389667232199235, - 2.1744490099377744673, - 2.1585958930438856781, - 2.1428764653998416425, - 2.1272876713173679737, - 2.1118265460190418108, - 2.0964902118017147637, - 2.0812758743932248696, - 2.0661808194905755036, - 2.0512024094685848641, - 2.0363380802487695916, - 2.0215853383189260770, - 2.0069417578945183144, - 1.9924049782135764992, - 1.9779727009573602295, - 1.9636426877895480401, - 1.9494127580071845659, - 1.9352807862970511135, - 1.9212447005915276767, - 1.9073024800183871196, - 1.8934521529393077332, - 1.8796917950722108462, - 1.8660195276928275962, - 1.8524335159111751661, - 1.8389319670188793980, - 1.8255131289035192212, - 1.8121752885263901413, - 1.7989167704602903934, - 1.7857359354841254047, - 1.7726311792313049959, - 1.7596009308890742369, - 1.7466436519460739352, - 1.7337578349855711926, - 1.7209420025219350428, - 1.7081947058780575683, - 1.6955145241015377061, - 1.6829000629175537544, - 1.6703499537164519163, - 1.6578628525741725325, - 1.6454374393037234057, - 1.6330724165359912048, - 1.6207665088282577216, - 1.6085184617988580769, - 1.5963270412864831349, - 1.5841910325326886695, - 1.5721092393862294810, - 1.5600804835278879161, - 1.5481036037145133070, - 1.5361774550410318943, - 1.5243009082192260050, - 1.5124728488721167573, - 1.5006921768428164936, - 1.4889578055167456003, - 1.4772686611561334579, - 1.4656236822457450411, - 1.4540218188487932264, - 1.4424620319720121876, - 1.4309432929388794104, - 1.4194645827699828254, - 1.4080248915695353509, - 1.3966232179170417110, - 1.3852585682631217189, - 1.3739299563284902176, - 1.3626364025050864742, - 1.3513769332583349176, - 1.3401505805295045843, - 1.3289563811371163220, - 1.3177933761763245480, - 1.3066606104151739482, - 1.2955571316866007210, - 1.2844819902750125450, - 1.2734342382962410994, - 1.2624129290696153434, - 1.2514171164808525098, - 1.2404458543344064544, - 1.2294981956938491599, - 1.2185731922087903071, - 1.2076698934267612830, - 1.1967873460884031665, - 1.1859245934042023557, - 1.1750806743109117687, - 1.1642546227056790397, - 1.1534454666557748056, - 1.1426522275816728928, - 1.1318739194110786733, - 1.1211095477013306083, - 1.1103581087274114281, - 1.0996185885325976575, - 1.0888899619385472598, - 1.0781711915113727024, - 1.0674612264799681530, - 1.0567590016025518414, - 1.0460634359770445503, - 1.0353734317905289496, - 1.0246878730026178052, - 1.0140056239570971074, - 1.0033255279156973717, - 0.99264640550727647009, - 0.98196705308506317914, - 0.97128624098390397896, - 0.96060271166866709917, - 0.94991517776407659940, - 0.93922231995526297952, - 0.92852278474721113999, - 0.91781518207004493915, - 0.90709808271569100600, - 0.89637001558989069006, - 0.88562946476175228052, - 0.87487486629102585352, - 0.86410460481100519511, - 0.85331700984237406386, - 0.84251035181036928333, - 0.83168283773427388393, - 0.82083260655441252290, - 0.80995772405741906620, - 0.79905617735548788109, - 0.78812586886949324977, - 0.77716460975913043936, - 0.76617011273543541328, - 0.75513998418198289808, - 0.74407171550050873971, - 0.73296267358436604916, - 0.72181009030875689912, - 0.71061105090965570413, - 0.69936248110323266174, - 0.68806113277374858613, - 0.67670356802952337911, - 0.66528614139267855405, - 0.65380497984766565353, - 0.64225596042453703448, - 0.63063468493349100113, - 0.61893645139487678178, - 0.60715622162030085137, - 0.59528858429150359384, - 0.58332771274877027785, - 0.57126731653258903915, - 0.55910058551154127652, - 0.54682012516331112550, - 0.53441788123716615385, - 0.52188505159213564105, - 0.50921198244365495319, - 0.49638804551867159754, - 0.48340149165346224782, - 0.47023927508216945338, - 0.45688684093142071279, - 0.44332786607355296305, - 0.42954394022541129589, - 0.41551416960035700100, - 0.40121467889627836229, - 0.38661797794112021568, - 0.37169214532991786118, - 0.35639976025839443721, - 0.34069648106484979674, - 0.32452911701691008547, - 0.30783295467493287307, - 0.29052795549123115167, - 0.27251318547846547924, - 0.25365836338591284433, - 0.23379048305967553619, - 0.21267151063096745264, - 0.18995868962243277774, - 0.16512762256418831796, - 0.13730498094001380420, - 0.10483850756582017915, - 0.063852163815003480173, - 0 + static final double[] X = { + 8.69711747013105, + 7.69711747013105, + 6.941033629377213, + 6.47837849383257, + 6.144164665772473, + 5.8821443157954, + 5.666410167454034, + 5.4828906275260625, + 5.323090505754399, + 5.181487281301501, + 5.054288489981305, + 4.938777085901251, + 4.832939741025113, + 4.735242996601741, + 4.644491885420085, + 4.559737061707351, + 4.480211746528422, + 4.405287693473573, + 4.334443680317273, + 4.267242480277366, + 4.203313713735184, + 4.1423408656640515, + 4.084051310408298, + 4.028208544647937, + 3.9746060666737884, + 3.9230625001354897, + 3.873417670399509, + 3.8255294185223367, + 3.779270992411668, + 3.7345288940397974, + 3.691201090237419, + 3.6491955157608538, + 3.6084288131289095, + 3.5688252656483375, + 3.530315889129344, + 3.49283765477406, + 3.4563328211327606, + 3.4207483572511204, + 3.386035442460302, + 3.35214903090011, + 3.319047470970749, + 3.286692171599069, + 3.2550473085704503, + 3.2240795652862646, + 3.1937579032122407, + 3.1640533580259733, + 3.134938858084441, + 3.1063890623398245, + 3.0783802152540907, + 3.0508900166154556, + 3.0238975044556766, + 2.9973829495161306, + 2.9713277599210897, + 2.9457143948950457, + 2.920526286512741, + 2.895747768600142, + 2.8713640120155364, + 2.847360965635189, + 2.8237253024500353, + 2.8004443702507382, + 2.777506146439757, + 2.7548991965623455, + 2.732612636194701, + 2.710636095867929, + 2.688959688741804, + 2.667573980773267, + 2.6464699631518096, + 2.6256390267977885, + 2.6050729387408356, + 2.5847638202141408, + 2.5647041263169053, + 2.54488662711187, + 2.525304390037828, + 2.505950763528594, + 2.48681936174021, + 2.467904050297365, + 2.4491989329782498, + 2.4306983392644197, + 2.4123968126888706, + 2.3942890999214583, + 2.376370140536141, + 2.3586350574093373, + 2.341079147703035, + 2.3236978743901964, + 2.30648685828358, + 2.2894418705322694, + 2.272558825553155, + 2.255833774367219, + 2.2392628983129086, + 2.2228425031110364, + 2.2065690132576634, + 2.19043896672322, + 2.1744490099377747, + 2.1585958930438855, + 2.1428764653998416, + 2.127287671317368, + 2.1118265460190417, + 2.0964902118017146, + 2.0812758743932247, + 2.0661808194905755, + 2.051202409468585, + 2.0363380802487696, + 2.021585338318926, + 2.006941757894518, + 1.9924049782135764, + 1.9779727009573602, + 1.963642687789548, + 1.9494127580071845, + 1.9352807862970511, + 1.9212447005915276, + 1.907302480018387, + 1.8934521529393078, + 1.8796917950722107, + 1.8660195276928275, + 1.852433515911175, + 1.8389319670188793, + 1.8255131289035191, + 1.8121752885263902, + 1.7989167704602904, + 1.7857359354841253, + 1.772631179231305, + 1.7596009308890743, + 1.746643651946074, + 1.7337578349855711, + 1.720942002521935, + 1.7081947058780576, + 1.6955145241015377, + 1.6829000629175537, + 1.670349953716452, + 1.6578628525741725, + 1.6454374393037234, + 1.6330724165359911, + 1.6207665088282577, + 1.6085184617988582, + 1.5963270412864832, + 1.5841910325326887, + 1.5721092393862295, + 1.5600804835278879, + 1.5481036037145133, + 1.5361774550410319, + 1.524300908219226, + 1.5124728488721169, + 1.5006921768428165, + 1.4889578055167456, + 1.4772686611561334, + 1.4656236822457451, + 1.4540218188487932, + 1.4424620319720123, + 1.4309432929388795, + 1.4194645827699828, + 1.4080248915695353, + 1.3966232179170417, + 1.3852585682631218, + 1.3739299563284901, + 1.3626364025050866, + 1.351376933258335, + 1.3401505805295046, + 1.3289563811371163, + 1.3177933761763245, + 1.306660610415174, + 1.2955571316866008, + 1.2844819902750126, + 1.2734342382962411, + 1.2624129290696153, + 1.2514171164808525, + 1.2404458543344064, + 1.229498195693849, + 1.2185731922087903, + 1.2076698934267613, + 1.196787346088403, + 1.1859245934042024, + 1.1750806743109117, + 1.1642546227056791, + 1.1534454666557747, + 1.1426522275816728, + 1.1318739194110787, + 1.1211095477013306, + 1.1103581087274115, + 1.0996185885325978, + 1.0888899619385473, + 1.0781711915113728, + 1.067461226479968, + 1.0567590016025519, + 1.0460634359770447, + 1.035373431790529, + 1.0246878730026179, + 1.0140056239570971, + 1.0033255279156974, + 0.9926464055072765, + 0.9819670530850632, + 0.9712862409839039, + 0.9606027116686671, + 0.9499151777640766, + 0.939222319955263, + 0.9285227847472112, + 0.917815182070045, + 0.907098082715691, + 0.8963700155898907, + 0.8856294647617523, + 0.8748748662910258, + 0.8641046048110052, + 0.853317009842374, + 0.8425103518103693, + 0.8316828377342739, + 0.8208326065544125, + 0.8099577240574191, + 0.7990561773554878, + 0.7881258688694932, + 0.7771646097591305, + 0.7661701127354354, + 0.7551399841819829, + 0.7440717155005088, + 0.7329626735843661, + 0.7218100903087569, + 0.7106110509096557, + 0.6993624811032326, + 0.6880611327737486, + 0.6767035680295234, + 0.6652861413926786, + 0.6538049798476656, + 0.642255960424537, + 0.630634684933491, + 0.6189364513948767, + 0.6071562216203008, + 0.5952885842915036, + 0.5833277127487703, + 0.571267316532589, + 0.5591005855115413, + 0.5468201251633111, + 0.5344178812371662, + 0.5218850515921356, + 0.509211982443655, + 0.4963880455186716, + 0.48340149165346225, + 0.47023927508216945, + 0.45688684093142073, + 0.44332786607355296, + 0.4295439402254113, + 0.415514169600357, + 0.4012146788962784, + 0.38661797794112024, + 0.37169214532991784, + 0.3563997602583944, + 0.3406964810648498, + 0.32452911701691006, + 0.3078329546749329, + 0.29052795549123117, + 0.2725131854784655, + 0.25365836338591286, + 0.23379048305967554, + 0.21267151063096745, + 0.18995868962243279, + 0.1651276225641883, + 0.1373049809400138, + 0.10483850756582018, + 0.06385216381500348, + 0.0 }; - private static final double[] Y = { - 0, - 0.00045413435384149675545, - 0.00096726928232717452884, - 0.0015362997803015723824, - 0.0021459677437189061793, - 0.0027887987935740759640, - 0.0034602647778369039855, - 0.0041572951208337952532, - 0.0048776559835423925804, - 0.0056196422072054831710, - 0.0063819059373191794422, - 0.0071633531836349841425, - 0.0079630774380170392396, - 0.0087803149858089752347, - 0.0096144136425022094101, - 0.010464810181029979488, - 0.011331013597834597488, - 0.012212592426255380661, - 0.013109164931254991070, - 0.014020391403181937334, - 0.014945968011691148079, - 0.015885621839973162490, - 0.016839106826039946359, - 0.017806200410911360563, - 0.018786700744696029497, - 0.019780424338009741737, - 0.020787204072578117603, - 0.021806887504283582125, - 0.022839335406385238829, - 0.023884420511558170348, - 0.024942026419731782971, - 0.026012046645134218076, - 0.027094383780955798424, - 0.028188948763978634421, - 0.029295660224637394015, - 0.030414443910466605492, - 0.031545232172893605499, - 0.032687963508959533317, - 0.033842582150874329031, - 0.035009037697397411067, - 0.036187284781931419754, - 0.037377282772959360128, - 0.038578995503074859626, - 0.039792391023374122670, - 0.041017441380414820816, - 0.042254122413316231413, - 0.043502413568888183301, - 0.044762297732943280694, - 0.046033761076175166762, - 0.047316792913181548703, - 0.048611385573379494401, - 0.049917534282706374944, - 0.051235237055126279830, - 0.052564494593071689595, - 0.053905310196046085104, - 0.055257689676697038322, - 0.056621641283742874438, - 0.057997175631200659098, - 0.059384305633420264487, - 0.060783046445479636051, - 0.062193415408540996150, - 0.063615431999807331076, - 0.065049117786753755036, - 0.066494496385339779043, - 0.067951593421936607770, - 0.069420436498728751675, - 0.070901055162371828426, - 0.072393480875708743023, - 0.073897746992364746308, - 0.075413888734058408453, - 0.076941943170480510100, - 0.078481949201606426042, - 0.080033947542319910023, - 0.081597980709237420930, - 0.083174093009632380354, - 0.084762330532368125386, - 0.086362741140756912277, - 0.087975374467270219300, - 0.089600281910032864534, - 0.091237516631040162057, - 0.092887133556043546523, - 0.094549189376055853718, - 0.096223742550432800103, - 0.097910853311492199618, - 0.099610583670637128826, - 0.10132299742595363588, - 0.10304816017125771553, - 0.10478613930657016928, - 0.10653700405000166218, - 0.10830082545103379867, - 0.11007767640518539026, - 0.11186763167005629731, - 0.11367076788274431301, - 0.11548716357863353664, - 0.11731689921155557057, - 0.11916005717532768467, - 0.12101672182667483729, - 0.12288697950954513498, - 0.12477091858083096578, - 0.12666862943751066518, - 0.12858020454522817870, - 0.13050573846833078225, - 0.13244532790138752023, - 0.13439907170221363078, - 0.13636707092642885841, - 0.13834942886358021406, - 0.14034625107486244210, - 0.14235764543247220043, - 0.14438372216063476473, - 0.14642459387834493787, - 0.14848037564386679222, - 0.15055118500103990354, - 0.15263714202744286154, - 0.15473836938446807312, - 0.15685499236936522013, - 0.15898713896931420572, - 0.16113493991759203183, - 0.16329852875190180795, - 0.16547804187493600915, - 0.16767361861725019322, - 0.16988540130252766513, - 0.17211353531532005700, - 0.17435816917135348788, - 0.17661945459049489581, - 0.17889754657247831241, - 0.18119260347549629488, - 0.18350478709776746150, - 0.18583426276219711495, - 0.18818119940425430485, - 0.19054576966319540013, - 0.19292814997677133873, - 0.19532852067956322315, - 0.19774706610509886464, - 0.20018397469191127727, - 0.20263943909370901930, - 0.20511365629383770880, - 0.20760682772422204205, - 0.21011915938898825914, - 0.21265086199297827522, - 0.21520215107537867786, - 0.21777324714870053264, - 0.22036437584335949720, - 0.22297576805812018050, - 0.22560766011668406495, - 0.22826029393071670664, - 0.23093391716962742173, - 0.23362878343743333945, - 0.23634515245705964715, - 0.23908329026244917002, - 0.24184346939887722761, - 0.24462596913189210901, - 0.24743107566532763894, - 0.25025908236886230967, - 0.25311029001562948171, - 0.25598500703041538015, - 0.25888354974901621678, - 0.26180624268936295243, - 0.26475341883506220209, - 0.26772541993204481808, - 0.27072259679906003167, - 0.27374530965280298302, - 0.27679392844851734458, - 0.27986883323697289920, - 0.28297041453878076010, - 0.28609907373707684673, - 0.28925522348967773308, - 0.29243928816189258772, - 0.29565170428126120948, - 0.29889292101558177099, - 0.30216340067569352897, - 0.30546361924459023541, - 0.30879406693456016794, - 0.31215524877417956945, - 0.31554768522712893632, - 0.31897191284495723773, - 0.32242848495608914289, - 0.32591797239355619822, - 0.32944096426413633091, - 0.33299806876180896713, - 0.33658991402867758144, - 0.34021714906678004560, - 0.34388044470450243010, - 0.34758049462163698567, - 0.35131801643748334681, - 0.35509375286678745925, - 0.35890847294874976196, - 0.36276297335481777335, - 0.36665807978151414890, - 0.37059464843514599421, - 0.37457356761590215193, - 0.37859575940958081092, - 0.38266218149600982112, - 0.38677382908413768115, - 0.39093173698479710717, - 0.39513698183329015336, - 0.39939068447523107877, - 0.40369401253053026739, - 0.40804818315203238238, - 0.41245446599716116772, - 0.41691418643300289465, - 0.42142872899761659635, - 0.42599954114303435739, - 0.43062813728845883923, - 0.43531610321563659758, - 0.44006510084235387501, - 0.44487687341454851593, - 0.44975325116275498919, - 0.45469615747461548049, - 0.45970761564213768669, - 0.46478975625042618067, - 0.46994482528395999841, - 0.47517519303737738299, - 0.48048336393045423016, - 0.48587198734188493564, - 0.49134386959403255500, - 0.49690198724154955294, - 0.50254950184134769289, - 0.50828977641064283495, - 0.51412639381474855788, - 0.52006317736823356823, - 0.52610421398361972602, - 0.53225388026304326945, - 0.53851687200286186590, - 0.54489823767243963663, - 0.55140341654064131685, - 0.55803828226258748140, - 0.56480919291240022434, - 0.57172304866482579008, - 0.57878735860284503057, - 0.58601031847726802755, - 0.59340090169173341521, - 0.60096896636523224742, - 0.60872538207962206507, - 0.61668218091520762326, - 0.62485273870366592605, - 0.63325199421436607968, - 0.64189671642726607018, - 0.65080583341457104881, - 0.66000084107899974178, - 0.66950631673192477684, - 0.67935057226476538741, - 0.68956649611707798890, - 0.70019265508278816709, - 0.71127476080507597882, - 0.72286765959357200702, - 0.73503809243142351530, - 0.74786862198519510742, - 0.76146338884989624862, - 0.77595685204011559675, - 0.79152763697249565519, - 0.80842165152300838005, - 0.82699329664305033399, - 0.84778550062398962096, - 0.87170433238120363669, - 0.90046992992574643800, - 0.93814368086217467916, - 1 + static final double[] Y = { + 0.0, + 4.5413435384149677E-4, + 9.672692823271745E-4, + 0.0015362997803015724, + 0.0021459677437189063, + 0.002788798793574076, + 0.003460264777836904, + 0.004157295120833795, + 0.004877655983542392, + 0.005619642207205483, + 0.006381905937319179, + 0.007163353183634984, + 0.00796307743801704, + 0.008780314985808975, + 0.00961441364250221, + 0.010464810181029979, + 0.011331013597834597, + 0.012212592426255381, + 0.013109164931254991, + 0.014020391403181938, + 0.014945968011691148, + 0.015885621839973163, + 0.016839106826039948, + 0.01780620041091136, + 0.01878670074469603, + 0.019780424338009743, + 0.020787204072578117, + 0.02180688750428358, + 0.02283933540638524, + 0.02388442051155817, + 0.024942026419731783, + 0.026012046645134217, + 0.0270943837809558, + 0.028188948763978636, + 0.029295660224637393, + 0.030414443910466604, + 0.03154523217289361, + 0.032687963508959535, + 0.03384258215087433, + 0.03500903769739741, + 0.03618728478193142, + 0.03737728277295936, + 0.03857899550307486, + 0.039792391023374125, + 0.04101744138041482, + 0.042254122413316234, + 0.04350241356888818, + 0.04476229773294328, + 0.04603376107617517, + 0.04731679291318155, + 0.0486113855733795, + 0.04991753428270637, + 0.05123523705512628, + 0.05256449459307169, + 0.05390531019604609, + 0.05525768967669704, + 0.05662164128374288, + 0.05799717563120066, + 0.059384305633420266, + 0.06078304644547963, + 0.062193415408540995, + 0.06361543199980733, + 0.06504911778675375, + 0.06649449638533977, + 0.0679515934219366, + 0.06942043649872875, + 0.07090105516237183, + 0.07239348087570874, + 0.07389774699236475, + 0.07541388873405841, + 0.0769419431704805, + 0.07848194920160642, + 0.0800339475423199, + 0.08159798070923742, + 0.08317409300963238, + 0.08476233053236812, + 0.08636274114075691, + 0.08797537446727022, + 0.08960028191003286, + 0.09123751663104016, + 0.09288713355604354, + 0.09454918937605586, + 0.0962237425504328, + 0.0979108533114922, + 0.09961058367063713, + 0.10132299742595363, + 0.10304816017125772, + 0.10478613930657017, + 0.10653700405000166, + 0.1083008254510338, + 0.11007767640518538, + 0.1118676316700563, + 0.11367076788274431, + 0.11548716357863353, + 0.11731689921155557, + 0.11916005717532768, + 0.12101672182667483, + 0.12288697950954514, + 0.12477091858083096, + 0.12666862943751067, + 0.12858020454522817, + 0.13050573846833077, + 0.13244532790138752, + 0.13439907170221363, + 0.13636707092642886, + 0.1383494288635802, + 0.14034625107486245, + 0.1423576454324722, + 0.14438372216063478, + 0.14642459387834494, + 0.1484803756438668, + 0.1505511850010399, + 0.15263714202744286, + 0.15473836938446808, + 0.15685499236936523, + 0.1589871389693142, + 0.16113493991759203, + 0.16329852875190182, + 0.165478041874936, + 0.1676736186172502, + 0.16988540130252766, + 0.17211353531532006, + 0.1743581691713535, + 0.17661945459049488, + 0.1788975465724783, + 0.1811926034754963, + 0.18350478709776746, + 0.1858342627621971, + 0.18818119940425432, + 0.1905457696631954, + 0.19292814997677135, + 0.19532852067956322, + 0.19774706610509887, + 0.20018397469191127, + 0.20263943909370902, + 0.2051136562938377, + 0.20760682772422204, + 0.21011915938898826, + 0.21265086199297828, + 0.21520215107537868, + 0.21777324714870053, + 0.2203643758433595, + 0.2229757680581202, + 0.22560766011668407, + 0.2282602939307167, + 0.2309339171696274, + 0.23362878343743335, + 0.23634515245705964, + 0.23908329026244918, + 0.24184346939887721, + 0.2446259691318921, + 0.24743107566532763, + 0.2502590823688623, + 0.25311029001562946, + 0.2559850070304154, + 0.25888354974901623, + 0.261806242689363, + 0.2647534188350622, + 0.2677254199320448, + 0.27072259679906, + 0.27374530965280297, + 0.27679392844851736, + 0.2798688332369729, + 0.28297041453878075, + 0.2860990737370768, + 0.28925522348967775, + 0.2924392881618926, + 0.2956517042812612, + 0.2988929210155818, + 0.3021634006756935, + 0.30546361924459026, + 0.3087940669345602, + 0.31215524877417955, + 0.31554768522712895, + 0.31897191284495724, + 0.32242848495608917, + 0.3259179723935562, + 0.3294409642641363, + 0.332998068761809, + 0.3365899140286776, + 0.34021714906678, + 0.3438804447045024, + 0.347580494621637, + 0.35131801643748334, + 0.35509375286678746, + 0.3589084729487498, + 0.3627629733548178, + 0.36665807978151416, + 0.370594648435146, + 0.37457356761590216, + 0.3785957594095808, + 0.38266218149600983, + 0.38677382908413765, + 0.3909317369847971, + 0.39513698183329016, + 0.3993906844752311, + 0.4036940125305303, + 0.4080481831520324, + 0.4124544659971612, + 0.4169141864330029, + 0.4214287289976166, + 0.42599954114303434, + 0.43062813728845883, + 0.4353161032156366, + 0.4400651008423539, + 0.4448768734145485, + 0.449753251162755, + 0.4546961574746155, + 0.4597076156421377, + 0.4647897562504262, + 0.46994482528396, + 0.4751751930373774, + 0.4804833639304542, + 0.4858719873418849, + 0.49134386959403253, + 0.49690198724154955, + 0.5025495018413477, + 0.5082897764106429, + 0.5141263938147486, + 0.5200631773682336, + 0.5261042139836197, + 0.5322538802630433, + 0.5385168720028619, + 0.5448982376724396, + 0.5514034165406413, + 0.5580382822625874, + 0.5648091929124002, + 0.5717230486648258, + 0.578787358602845, + 0.586010318477268, + 0.5934009016917334, + 0.6009689663652322, + 0.608725382079622, + 0.6166821809152077, + 0.624852738703666, + 0.6332519942143661, + 0.6418967164272661, + 0.6508058334145711, + 0.6600008410789997, + 0.6695063167319247, + 0.6793505722647654, + 0.689566496117078, + 0.7001926550827882, + 0.711274760805076, + 0.722867659593572, + 0.7350380924314235, + 0.7478686219851951, + 0.7614633888498963, + 0.7759568520401156, + 0.7915276369724956, + 0.8084216515230084, + 0.8269932966430503, + 0.8477855006239896, + 0.8717043323812036, + 0.9004699299257465, + 0.9381436808621747, + 1.0 }; // use of strictfp to make random values platform-independent diff --git a/src/main/java/com/dynatrace/hash4j/similarity/FastSimHashPolicy_v1.java b/src/main/java/com/dynatrace/hash4j/similarity/FastSimHashPolicy_v1.java index 116f3a68..b870e931 100644 --- a/src/main/java/com/dynatrace/hash4j/similarity/FastSimHashPolicy_v1.java +++ b/src/main/java/com/dynatrace/hash4j/similarity/FastSimHashPolicy_v1.java @@ -62,6 +62,7 @@ private class Hasher implements SimilarityHasher { private final PseudoRandomGenerator pseudoRandomGenerator = pseudoRandomGeneratorProvider.create(); + @Override public byte[] compute(ElementHashProvider elementHashProvider) { requireNonNull(elementHashProvider); @@ -118,7 +119,7 @@ public byte[] compute(ElementHashProvider elementHashProvider) { } } - final long limit = numberOfElements >>> 1; + final long limit = (long) (numberOfElements >>> 1); return packedArrayHandler.create( i -> (counts[i] + (i & (~numberOfElements & 1)) > limit) ? 1L : 0L, numberOfComponents); } diff --git a/src/main/java/com/dynatrace/hash4j/similarity/SimHashPolicy_v1.java b/src/main/java/com/dynatrace/hash4j/similarity/SimHashPolicy_v1.java index 82a41156..e7e6b897 100644 --- a/src/main/java/com/dynatrace/hash4j/similarity/SimHashPolicy_v1.java +++ b/src/main/java/com/dynatrace/hash4j/similarity/SimHashPolicy_v1.java @@ -41,6 +41,7 @@ private class Hasher implements SimilarityHasher { private final PseudoRandomGenerator pseudoRandomGenerator = pseudoRandomGeneratorProvider.create(); + @Override public byte[] compute(ElementHashProvider elementHashProvider) { requireNonNull(elementHashProvider); @@ -74,7 +75,7 @@ public byte[] compute(ElementHashProvider elementHashProvider) { } } - final long limit = numberOfElements >>> 1; + final long limit = (long) (numberOfElements >>> 1); return packedArrayHandler.create( i -> (counts[i] + (i & (~numberOfElements & 1)) > limit) ? 1L : 0L, numberOfComponents); } diff --git a/src/main/java/com/dynatrace/hash4j/similarity/SuperMinHashPolicy_v1b.java b/src/main/java/com/dynatrace/hash4j/similarity/SuperMinHashPolicy_v1b.java index 8722371c..4df08377 100644 --- a/src/main/java/com/dynatrace/hash4j/similarity/SuperMinHashPolicy_v1b.java +++ b/src/main/java/com/dynatrace/hash4j/similarity/SuperMinHashPolicy_v1b.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Dynatrace LLC + * Copyright 2022-2023 Dynatrace LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -161,7 +161,7 @@ int estimateCycleLimit(int numberOfDistinctElements) { 1, Math.ceil( numberOfComponents - * (-Math.expm1(cycleLimitEstimationConstant / numberOfDistinctElements)))); + * -Math.expm1(cycleLimitEstimationConstant / numberOfDistinctElements))); } @Override diff --git a/src/main/java/com/dynatrace/hash4j/util/PackedArray.java b/src/main/java/com/dynatrace/hash4j/util/PackedArray.java index 0c49b857..fa60011f 100644 --- a/src/main/java/com/dynatrace/hash4j/util/PackedArray.java +++ b/src/main/java/com/dynatrace/hash4j/util/PackedArray.java @@ -903,21 +903,21 @@ public int numEqualComponents(byte[] array1, byte[] array2, int length) { if (length >= 16) { int l1 = getShort(array1, bytePos); int l2 = getShort(array2, bytePos); - result += Integer.bitCount((~(l1 ^ l2)) & 0xFFFF); + result += Integer.bitCount(~(l1 ^ l2) & 0xFFFF); bytePos += 2; length -= 16; } if (length >= 8) { int l1 = array1[bytePos]; int l2 = array2[bytePos]; - result += Integer.bitCount((~(l1 ^ l2)) & 0xFF); + result += Integer.bitCount(~(l1 ^ l2) & 0xFF); bytePos += 1; length -= 8; } if (length > 0) { int l1 = array1[bytePos]; int l2 = array2[bytePos]; - result += Integer.bitCount((~(l1 ^ l2)) & ((0xFF << length) >>> 8)); + result += Integer.bitCount(~(l1 ^ l2) & ((0xFF << length) >>> 8)); } return result; } diff --git a/src/test/java/com/dynatrace/hash4j/distinctcount/BigInt.java b/src/test/java/com/dynatrace/hash4j/distinctcount/BigInt.java index cebc3fd9..2b528a1b 100644 --- a/src/test/java/com/dynatrace/hash4j/distinctcount/BigInt.java +++ b/src/test/java/com/dynatrace/hash4j/distinctcount/BigInt.java @@ -21,7 +21,7 @@ import java.math.BigInteger; import java.util.Objects; -public class BigInt implements Comparable { +public final class BigInt implements Comparable { private static final BigInteger TWO_POW_63 = BigInteger.valueOf(2).pow(63); private static final double TWO_POW_PLUS_63_DOUBLE = Math.pow(2., 63); @@ -131,7 +131,7 @@ public boolean isPositive() { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (!(o instanceof BigInt)) return false; BigInt bigInt = (BigInt) o; return low == bigInt.low && high == bigInt.high; } diff --git a/src/test/java/com/dynatrace/hash4j/distinctcount/EstimationErrorSimulationUtil.java b/src/test/java/com/dynatrace/hash4j/distinctcount/EstimationErrorSimulationUtil.java index c88f689f..50dceeab 100644 --- a/src/test/java/com/dynatrace/hash4j/distinctcount/EstimationErrorSimulationUtil.java +++ b/src/test/java/com/dynatrace/hash4j/distinctcount/EstimationErrorSimulationUtil.java @@ -21,6 +21,7 @@ import com.dynatrace.hash4j.random.PseudoRandomGeneratorProvider; import java.io.FileWriter; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.ExecutionException; import java.util.concurrent.ForkJoinPool; @@ -175,7 +176,7 @@ void doSimulation( .mapToDouble(c -> c.getpToAsymptoticRelativeStandardError().applyAsDouble(p)) .toArray(); - try (FileWriter writer = new FileWriter(outputFile)) { + try (FileWriter writer = new FileWriter(outputFile, StandardCharsets.UTF_8)) { writer.write( "sketch_name=" + sketchName diff --git a/src/test/java/com/dynatrace/hash4j/distinctcount/UltraLogLogTest.java b/src/test/java/com/dynatrace/hash4j/distinctcount/UltraLogLogTest.java index 7dd26825..4364cc6d 100644 --- a/src/test/java/com/dynatrace/hash4j/distinctcount/UltraLogLogTest.java +++ b/src/test/java/com/dynatrace/hash4j/distinctcount/UltraLogLogTest.java @@ -92,7 +92,7 @@ void testRegisterPacking() { assertThat(UltraLogLog.pack(12)).isEqualTo((byte) 14); assertThat(UltraLogLog.pack(1L << (12 - 1))).isEqualTo((byte) 44); assertThat(UltraLogLog.pack(1L << 12)).isEqualTo((byte) 48); - assertThat(UltraLogLog.pack((1L << (12 - 1)) | (1L << (12)))).isEqualTo((byte) 50); + assertThat(UltraLogLog.pack((1L << (12 - 1)) | (1L << 12))).isEqualTo((byte) 50); assertThat(UltraLogLog.pack(1L << (12 + 1))).isEqualTo((byte) 52); assertThat(UltraLogLog.pack(0x8000000000000000L)).isEqualTo((byte) 252); assertThat(UltraLogLog.pack(0xFFFFFFFFFFFFFFFFL)).isEqualTo((byte) 255); @@ -158,7 +158,7 @@ void testUpdateValues() { for (int p = MIN_P; p <= MAX_P; ++p) { for (int i = p; i <= 64; ++i) { long hash = 0xFFFFFFFFFFFFFFFFL >>> 1 >>> (i - 1); - int nlz = Long.numberOfLeadingZeros(~((~hash) << p)); + int nlz = Long.numberOfLeadingZeros(~(~hash << p)); assertThat(i - p + 1).isEqualTo(nlz + 1); assertThat(((UltraLogLog.create(p).add(hash).getState()[0] & 0xFF) >>> 2) + 2 - p) .isEqualTo(nlz + 1); @@ -769,12 +769,6 @@ private static byte mapRegisterFromReferenceDefinition(byte r, int p) { return (byte) (r + 4 * (p - 2)); } - // this function maps a register value to the corresponding value as defined in the paper - private static byte mapRegisterToReferenceDefinition(byte r, int p) { - if (r == 0) return 0; - return (byte) (r - 4 * (p - 2)); - } - @Test void testScaledRegisterStateChangeProbability() { for (int p = MIN_P; p <= MAX_P; ++p) { diff --git a/src/test/java/com/dynatrace/hash4j/file/FileHashingDemo.java b/src/test/java/com/dynatrace/hash4j/file/FileHashingDemo.java index 0c090bd5..c9a7304b 100644 --- a/src/test/java/com/dynatrace/hash4j/file/FileHashingDemo.java +++ b/src/test/java/com/dynatrace/hash4j/file/FileHashingDemo.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Path; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -32,7 +33,7 @@ void demoImohash(@TempDir Path path) throws IOException { // create some file in the given path File file = path.resolve("test.txt").toFile(); - try (FileWriter fileWriter = new FileWriter(file)) { + try (FileWriter fileWriter = new FileWriter(file, StandardCharsets.UTF_8)) { fileWriter.write("this is the file content"); } diff --git a/src/test/java/com/dynatrace/hash4j/file/Imohash1_0_2Test.java b/src/test/java/com/dynatrace/hash4j/file/Imohash1_0_2Test.java index 02b471c3..a2bf45a0 100644 --- a/src/test/java/com/dynatrace/hash4j/file/Imohash1_0_2Test.java +++ b/src/test/java/com/dynatrace/hash4j/file/Imohash1_0_2Test.java @@ -227,6 +227,7 @@ void testEOFExceptionDuringRead(boolean throwExceptionWhenEOF) { .isThrownBy(() -> imohash.hashInputStreamTo128Bits(testInputStream, 2)); } + @SuppressWarnings("InputStreamSlowMultibyteRead") private static class TestInputStream extends InputStream { private long count = 0; private long totalLength = Long.MAX_VALUE; diff --git a/src/test/java/com/dynatrace/hash4j/hashing/AbstractHashSinkPutUnorderedIterableTest.java b/src/test/java/com/dynatrace/hash4j/hashing/AbstractHashSinkPutUnorderedIterableTest.java index 1f97b5ac..dca6d267 100644 --- a/src/test/java/com/dynatrace/hash4j/hashing/AbstractHashSinkPutUnorderedIterableTest.java +++ b/src/test/java/com/dynatrace/hash4j/hashing/AbstractHashSinkPutUnorderedIterableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Dynatrace LLC + * Copyright 2022-2023 Dynatrace LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +48,7 @@ void testContributeUnorderedIterableViaLong() { HashFunnel> funnelB = (set, out) -> out.putUnorderedIterable( - set::iterator, + asIterable(set), s -> Hashing.murmur3_128().hashToLong(s, (data, out1) -> out1.putString(data))); long hash1a = Hashing.murmur3_128().hashToLong(set1, funnelA); @@ -154,7 +154,7 @@ void testContributeOrderedIterable() { HashFunnel> funnelA = (list, out) -> out.putOrderedIterable(list, (s, o) -> o.putString(s)); HashFunnel> funnelB = - (list, out) -> out.putOrderedIterable(list::iterator, (s, o) -> o.putString(s)); + (list, out) -> out.putOrderedIterable(asIterable(list), (s, o) -> o.putString(s)); long hash1a = Hashing.murmur3_128().hashToLong(list1, funnelA); long hash2a = Hashing.murmur3_128().hashToLong(list2, funnelA); @@ -195,7 +195,7 @@ void testPutUnorderedIterable() { List longList = asLongRandomAccessList(values); sinkRandomAccessList.putUnorderedIterable(longList, v -> v); sinkCollection.putUnorderedIterable(asCollection(longList), v -> v); - sinkIterable.putUnorderedIterable(longList::iterator, v -> v); + sinkIterable.putUnorderedIterable(asIterable(longList), v -> v); assertThat(sinkRandomAccessList.getData()).isEqualTo(expected); assertThat(sinkCollection.getData()).isEqualTo(expected); diff --git a/src/test/java/com/dynatrace/hash4j/hashing/AbstractHasherTest.java b/src/test/java/com/dynatrace/hash4j/hashing/AbstractHasherTest.java index 639aeaf4..ecc6cbec 100644 --- a/src/test/java/com/dynatrace/hash4j/hashing/AbstractHasherTest.java +++ b/src/test/java/com/dynatrace/hash4j/hashing/AbstractHasherTest.java @@ -554,7 +554,7 @@ void testPutShortArray(Hasher hasher) { random.nextLong(), r -> { short[] array = new short[maxArraySize]; - IntStream.range(0, maxArraySize).forEach(i -> array[i] = (short) (r.nextInt())); + IntStream.range(0, maxArraySize).forEach(i -> array[i] = (short) r.nextInt()); return h -> h.putShortArray(array); }); } @@ -571,7 +571,7 @@ void testPutCharArray(Hasher hasher) { random.nextLong(), r -> { char[] array = new char[maxArraySize]; - IntStream.range(0, maxArraySize).forEach(i -> array[i] = (char) (r.nextInt())); + IntStream.range(0, maxArraySize).forEach(i -> array[i] = (char) r.nextInt()); return h -> h.putCharArray(array); }); } @@ -1158,7 +1158,7 @@ public int length() { @Override public char charAt(int index) { - return (char) (index * 0x5851f42d4c957f2dL >>> 48); + return (char) ((index * 0x5851f42d4c957f2dL) >>> 48); } @NotNull diff --git a/src/test/java/com/dynatrace/hash4j/hashing/HashValue128Test.java b/src/test/java/com/dynatrace/hash4j/hashing/HashValue128Test.java index d9a7a8d0..91ab14b6 100644 --- a/src/test/java/com/dynatrace/hash4j/hashing/HashValue128Test.java +++ b/src/test/java/com/dynatrace/hash4j/hashing/HashValue128Test.java @@ -65,7 +65,7 @@ void testEquals() { assertThat(hash1a.equals(hash2)).isFalse(); assertThat(hash1a.equals(hash3)).isFalse(); assertThat(hash1a.equals(hash4)).isFalse(); - assertThat(hash1a.equals((new Object()))).isFalse(); + assertThat(hash1a.equals(new Object())).isFalse(); } @Test diff --git a/src/test/java/com/dynatrace/hash4j/hashing/TestHashStream.java b/src/test/java/com/dynatrace/hash4j/hashing/TestHashStream.java index a0b4c582..93df81b4 100644 --- a/src/test/java/com/dynatrace/hash4j/hashing/TestHashStream.java +++ b/src/test/java/com/dynatrace/hash4j/hashing/TestHashStream.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Dynatrace LLC + * Copyright 2022-2023 Dynatrace LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ public int getHashBitSize() { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (!(o instanceof TestHashStream)) return false; TestHashStream that = (TestHashStream) o; return size == that.size && Arrays.equals(data, that.data); } diff --git a/src/test/java/com/dynatrace/hash4j/random/AbstractPseudoRandomGeneratorTest.java b/src/test/java/com/dynatrace/hash4j/random/AbstractPseudoRandomGeneratorTest.java index 1b41a702..d88457c7 100644 --- a/src/test/java/com/dynatrace/hash4j/random/AbstractPseudoRandomGeneratorTest.java +++ b/src/test/java/com/dynatrace/hash4j/random/AbstractPseudoRandomGeneratorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Dynatrace LLC + * Copyright 2022-2023 Dynatrace LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -93,7 +93,7 @@ void testUniformIntWithSpecialParameters() { void testStability() { PseudoRandomGenerator prg = createPseudoRandomGenerator(); for (int c = 0; c < 3; ++c) { - HashStream64 hashStream = Hashing.komihash4_3().hashStream(); + HashStream64 hashStream = Hashing.komihash5_0().hashStream(); prg.reset(0x2953eb15d353f9bdL); for (int i = 0; i < 1000; ++i) { hashStream.putLong(prg.nextLong()); @@ -107,6 +107,9 @@ void testStability() { for (int i = 1; i < 1000; ++i) { hashStream.putInt(prg.uniformInt(Integer.MAX_VALUE / i)); } + for (int i = 1; i < 1000; ++i) { + hashStream.putDouble(prg.nextExponential()); + } assertThat(hashStream.getAsLong()).isEqualTo(getExpectedStabilityCheckSum()); } } diff --git a/src/test/java/com/dynatrace/hash4j/random/RandomExponentialUtilTest.java b/src/test/java/com/dynatrace/hash4j/random/RandomExponentialUtilTest.java index 6c9d3478..72ce44ad 100644 --- a/src/test/java/com/dynatrace/hash4j/random/RandomExponentialUtilTest.java +++ b/src/test/java/com/dynatrace/hash4j/random/RandomExponentialUtilTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Dynatrace LLC + * Copyright 2022-2023 Dynatrace LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/test/java/com/dynatrace/hash4j/random/SplitMix64_v1Test.java b/src/test/java/com/dynatrace/hash4j/random/SplitMix64_v1Test.java index 214d1a01..39c31341 100644 --- a/src/test/java/com/dynatrace/hash4j/random/SplitMix64_v1Test.java +++ b/src/test/java/com/dynatrace/hash4j/random/SplitMix64_v1Test.java @@ -54,6 +54,6 @@ protected PseudoRandomGenerator createPseudoRandomGenerator() { @Override protected long getExpectedStabilityCheckSum() { - return 4691221998854044216L; + return 0x6a781f39f817d0a6L; } } diff --git a/src/test/java/com/dynatrace/hash4j/testutils/TestUtils.java b/src/test/java/com/dynatrace/hash4j/testutils/TestUtils.java index c54b6a39..53817d75 100644 --- a/src/test/java/com/dynatrace/hash4j/testutils/TestUtils.java +++ b/src/test/java/com/dynatrace/hash4j/testutils/TestUtils.java @@ -106,6 +106,7 @@ public CharSequence subSequence(int start, int end) { return byteArrayToCharSequence(y); } + @SuppressWarnings("UnnecessaryStringBuilder") @Override public String toString() { return new StringBuilder(length()).append(this).toString(); diff --git a/src/test/java/com/dynatrace/hash4j/testutils/TestUtilsTest.java b/src/test/java/com/dynatrace/hash4j/testutils/TestUtilsTest.java index e3fc554b..c70fecf1 100644 --- a/src/test/java/com/dynatrace/hash4j/testutils/TestUtilsTest.java +++ b/src/test/java/com/dynatrace/hash4j/testutils/TestUtilsTest.java @@ -40,10 +40,10 @@ void testByteArrayToCharSequence() { (byte) 0xef }; CharSequence charSequence = TestUtils.byteArrayToCharSequence(expected); - assertThat(charSequence.charAt(0)).isEqualTo((char) (0x2301)); - assertThat(charSequence.charAt(1)).isEqualTo((char) (0x6745)); - assertThat(charSequence.charAt(2)).isEqualTo((char) (0xab89)); - assertThat(charSequence.charAt(3)).isEqualTo((char) (0xefcd)); + assertThat(charSequence.charAt(0)).isEqualTo((char) 0x2301); + assertThat(charSequence.charAt(1)).isEqualTo((char) 0x6745); + assertThat(charSequence.charAt(2)).isEqualTo((char) 0xab89); + assertThat(charSequence.charAt(3)).isEqualTo((char) 0xefcd); assertThat(charSequence) .hasToString(String.valueOf((char) 0x2301) + (char) 0x6745 + (char) 0xab89 + (char) 0xefcd); diff --git a/src/test/java/com/dynatrace/hash4j/util/PackedArrayTest.java b/src/test/java/com/dynatrace/hash4j/util/PackedArrayTest.java index d17c86be..874747d7 100644 --- a/src/test/java/com/dynatrace/hash4j/util/PackedArrayTest.java +++ b/src/test/java/com/dynatrace/hash4j/util/PackedArrayTest.java @@ -37,7 +37,7 @@ private static List getBitSizes() { private static void assertEquals(long[] expected, byte[] actual, PackedArrayHandler handler) { int bitSize = handler.getBitSize(); - long mask = (bitSize > 0) ? (0xFFFFFFFFFFFFFFFFL >>> (-bitSize)) : 0; + long mask = (bitSize > 0) ? (0xFFFFFFFFFFFFFFFFL >>> -bitSize) : 0; for (int i = 0; i < expected.length; ++i) { long expectedValue = expected[i] & mask; long actualValue = handler.get(actual, i);