Skip to content

Commit

Permalink
xxh3 64bit implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
oertl committed Aug 1, 2024
1 parent 6d02259 commit 65a0652
Show file tree
Hide file tree
Showing 11 changed files with 1,223 additions and 25 deletions.
18 changes: 13 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ plugins {
id 'maven-publish'
id 'signing'
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
id "com.palantir.revapi" version "1.7.0"
id "net.ltgt.errorprone" version "4.0.1"
id 'com.palantir.revapi' version '1.7.0'
id 'net.ltgt.errorprone' version '4.0.1'
}

repositories {
Expand Down Expand Up @@ -84,9 +84,9 @@ version = '0.17.0'


spotless {
def googleJavaFormatVersion = '1.19.2'
def googleJavaFormatVersion = '1.23.0'
def eclipseCdtVersion = '11.3'
def blackVersion = '24.3.0'
def blackVersion = '24.4.2'
def greclipseVersion = '4.29'

ratchetFrom 'origin/main'
Expand Down Expand Up @@ -120,7 +120,8 @@ spotless {
'src/main/java/com/dynatrace/hash4j/hashing/FarmHashNa.java',\
'src/main/java/com/dynatrace/hash4j/hashing/FarmHashUo.java',\
'src/main/java/com/dynatrace/hash4j/random/SplitMix64V1.java',\
'src/main/java/com/dynatrace/hash4j/random/RandomExponentialUtil.java'
'src/main/java/com/dynatrace/hash4j/random/RandomExponentialUtil.java',\
'src/main/java/com/dynatrace/hash4j/hashing/XXH3_64.java'
}
format 'javaImohash', JavaExtension, {
importOrder()
Expand Down Expand Up @@ -171,6 +172,13 @@ spotless {
licenseHeader readJavaLicense('APACHE_2_0_DYNATRACE') + '\n\n' + readJavaLicense('APACHE_2_0_GUAVA')
target 'src/main/java/com/dynatrace/hash4j/consistent/ConsistentJumpBucketHasher.java'
}
format 'javaXXH', JavaExtension, {
importOrder()
removeUnusedImports()
googleJavaFormat(googleJavaFormatVersion)
licenseHeader readJavaLicense('APACHE_2_0_DYNATRACE') + '\n\n' + readJavaLicense('APACHE_2_0_XXH')
target 'src/main/java/com/dynatrace/hash4j/hashing/XXH3_64.java'
}
}

sonarqube {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down
19 changes: 19 additions & 0 deletions licenses/APACHE_2_0_XXH.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
This implementation was derived from

https://github.com/OpenHFT/Zero-Allocation-Hashing/blob/zero-allocation-hashing-0.16/src/main/java/net/openhft/hashing/XXH3.java

which was published under the license below:

Copyright 2015 Higher Frequency Trading http://www.higherfrequencytrading.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2022-2024 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dynatrace.hash4j.hashing;

public class XXH3_64PerformanceTest extends AbstactHasher64PerformanceTest {

private static final Hasher64 HASHER_INSTANCE = Hashing.xxh3_64();

@Override
protected Hasher64 getHasherInstance() {
return HASHER_INSTANCE;
}
}
29 changes: 29 additions & 0 deletions src/main/java/com/dynatrace/hash4j/hashing/Hashing.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,33 @@ public static Hasher64 farmHashUo(long seed) {
public static Hasher64 farmHashUo(long seed0, long seed1) {
return FarmHashUo.create(seed0, seed1);
}

/**
* Returns a {@link Hasher64} implementing the 64-bit XXH3 algorithm.
*
* <p>This implementation is compatible with the C++ reference implementation of {@code
* XXH3_64bits} defined in <a
* href="https://github.com/Cyan4973/xxHash/blob/v0.8.2/xxhash.h">xxhash.h</a> on an Intel x86
* architecture.
*
* @return a hasher instance
*/
public static Hasher64 xxh3_64() {
return XXH3_64.create();
}

/**
* Returns a {@link Hasher64} implementing the 64-bit XXH3 algorithm using the given seed value.
*
* <p>This implementation is compatible with the C++ reference implementation of {@code
* XXH3_64bits_withSeed} defined in <a
* href="https://github.com/Cyan4973/xxHash/blob/v0.8.2/xxhash.h">xxhash.h</a> on an Intel x86
* architecture.
*
* @param seed the seed value
* @return a hasher instance
*/
public static Hasher64 xxh3_64(long seed) {
return XXH3_64.create(seed);
}
}
30 changes: 15 additions & 15 deletions src/main/java/com/dynatrace/hash4j/hashing/Murmur3_128.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,51 +127,51 @@ public HashValue128 hashBytesTo128Bits(byte[] input, int off, int len) {
switch (len & 15) {
case 15:
k2 ^= (input[off + 14] & 0xFFL) << 48;
// fallthrough
// fallthrough
case 14:
k2 ^= (input[off + 13] & 0xFFL) << 40;
// fallthrough
// fallthrough
case 13:
k2 ^= (input[off + 12] & 0xFFL) << 32;
// fallthrough
// fallthrough
case 12:
k2 ^= (input[off + 11] & 0xFFL) << 24;
// fallthrough
// fallthrough
case 11:
k2 ^= (input[off + 10] & 0xFFL) << 16;
// fallthrough
// fallthrough
case 10:
k2 ^= (input[off + 9] & 0xFFL) << 8;
// fallthrough
// fallthrough
case 9:
k2 ^= input[off + 8] & 0xFFL;
h2 ^= mixK2(k2);
// fallthrough
// fallthrough
case 8:
k1 ^= (long) input[off + 7] << 56;
// fallthrough
// fallthrough
case 7:
k1 ^= (input[off + 6] & 0xFFL) << 48;
// fallthrough
// fallthrough
case 6:
k1 ^= (input[off + 5] & 0xFFL) << 40;
// fallthrough
// fallthrough
case 5:
k1 ^= (input[off + 4] & 0xFFL) << 32;
// fallthrough
// fallthrough
case 4:
k1 ^= (input[off + 3] & 0xFFL) << 24;
// fallthrough
// fallthrough
case 3:
k1 ^= (input[off + 2] & 0xFFL) << 16;
// fallthrough
// fallthrough
case 2:
k1 ^= (input[off + 1] & 0xFFL) << 8;
// fallthrough
// fallthrough
case 1:
k1 ^= input[off] & 0xFFL;
h1 ^= mixK1(k1);
// fallthrough
// fallthrough
default:
// do nothing
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/dynatrace/hash4j/hashing/Murmur3_32.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ public int hashBytesToInt(byte[] input, int off, int len) {
switch (len & 3) {
case 3:
k1 ^= (input[off + 2] & 0xFF) << 16;
// fallthrough
// fallthrough
case 2:
k1 ^= (input[off + 1] & 0xFF) << 8;
// fallthrough
// fallthrough
case 1:
k1 ^= (input[off] & 0xFF);
k1 = mixK1(k1);
h1 ^= k1;
// fallthrough
// fallthrough
default:
// do nothing
}
Expand Down
Loading

0 comments on commit 65a0652

Please sign in to comment.