Skip to content

Commit

Permalink
Merge pull request #322 from dynatrace-oss/xxh3-128
Browse files Browse the repository at this point in the history
Xxh3 128
  • Loading branch information
oertl authored Feb 3, 2025
2 parents 09453cb + f15110a commit 6460821
Show file tree
Hide file tree
Showing 47 changed files with 2,201 additions and 953 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ spotless {
'src/main/java/com/dynatrace/hash4j/consistent/ConsistentJumpBucketHasher.java'
]),
new Tuple3('javaXXH', 'APACHE_2_0_XXH',[
'src/main/java/com/dynatrace/hash4j/hashing/XXH3_64.java'
'src/main/java/com/dynatrace/hash4j/hashing/XXH3_64.java',
'src/main/java/com/dynatrace/hash4j/hashing/XXH3_128.java',
'src/main/java/com/dynatrace/hash4j/hashing/XXH3Base.java'
])
]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2022-2025 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;

import org.openjdk.jmh.infra.Blackhole;

public abstract class AbstactHasher128PerformanceTest extends AbstractPerformanceTest {

protected static final HashFunnel<CharSequence> CHARS_FUNNEL = (s, sink) -> sink.putChars(s);
protected static final HashFunnel<byte[]> BYTES_FUNNEL = (s, sink) -> sink.putBytes(s);

@Override
protected void hashObject(TestObject testObject, Blackhole blackhole) {
blackhole.consume(getHasherInstance().hashTo128Bits(testObject, TestObject::contributeToHash));
}

@Override
protected void hashBytesDirect(byte[] b, Blackhole blackhole) {
blackhole.consume(getHasherInstance().hashBytesTo128Bits(b));
}

@Override
protected void hashBytesIndirect(byte[] b, Blackhole blackhole) {
blackhole.consume(getHasherInstance().hashTo128Bits(b, BYTES_FUNNEL));
}

@Override
protected void hashCharsDirect(String s, Blackhole blackhole) {
blackhole.consume(getHasherInstance().hashCharsTo128Bits(s));
}

@Override
protected void hashCharsIndirect(String s, Blackhole blackhole) {
blackhole.consume(getHasherInstance().hashTo128Bits(s, CHARS_FUNNEL));
}

protected abstract Hasher128 getHasherInstance();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,34 +15,36 @@
*/
package com.dynatrace.hash4j.hashing;

import org.openjdk.jmh.infra.Blackhole;

public abstract class AbstactHasher32PerformanceTest extends AbstractPerformanceTest {

protected static final HashFunnel<CharSequence> CHARS_FUNNEL = (s, sink) -> sink.putChars(s);
protected static final HashFunnel<byte[]> BYTES_FUNNEL = (s, sink) -> sink.putBytes(s);

@Override
protected long hashObject(TestObject testObject) {
return getHasherInstance().hashToInt(testObject, TestObject::contributeToHash);
protected void hashObject(TestObject testObject, Blackhole blackhole) {
blackhole.consume(getHasherInstance().hashToInt(testObject, TestObject::contributeToHash));
}

@Override
protected long hashBytesDirect(byte[] b) {
return getHasherInstance().hashBytesToInt(b);
protected void hashBytesDirect(byte[] b, Blackhole blackhole) {
blackhole.consume(getHasherInstance().hashBytesToInt(b));
}

@Override
protected long hashCharsDirect(String c) {
return getHasherInstance().hashCharsToInt(c);
protected void hashCharsDirect(String c, Blackhole blackhole) {
blackhole.consume(getHasherInstance().hashCharsToInt(c));
}

@Override
protected long hashCharsIndirect(String s) {
return getHasherInstance().hashToInt(s, CHARS_FUNNEL);
protected void hashCharsIndirect(String s, Blackhole blackhole) {
blackhole.consume(getHasherInstance().hashToInt(s, CHARS_FUNNEL));
}

@Override
protected long hashBytesIndirect(byte[] b) {
return getHasherInstance().hashToInt(b, BYTES_FUNNEL);
protected void hashBytesIndirect(byte[] b, Blackhole blackhole) {
blackhole.consume(getHasherInstance().hashToInt(b, BYTES_FUNNEL));
}

protected abstract Hasher32 getHasherInstance();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,34 +15,36 @@
*/
package com.dynatrace.hash4j.hashing;

import org.openjdk.jmh.infra.Blackhole;

public abstract class AbstactHasher64PerformanceTest extends AbstractPerformanceTest {

protected static final HashFunnel<CharSequence> CHARS_FUNNEL = (s, sink) -> sink.putChars(s);
protected static final HashFunnel<byte[]> BYTES_FUNNEL = (s, sink) -> sink.putBytes(s);

@Override
protected long hashObject(TestObject testObject) {
return getHasherInstance().hashToLong(testObject, TestObject::contributeToHash);
protected void hashObject(TestObject testObject, Blackhole blackhole) {
blackhole.consume(getHasherInstance().hashToLong(testObject, TestObject::contributeToHash));
}

@Override
protected long hashBytesDirect(byte[] b) {
return getHasherInstance().hashBytesToLong(b);
protected void hashBytesDirect(byte[] b, Blackhole blackhole) {
blackhole.consume(getHasherInstance().hashBytesToLong(b));
}

@Override
protected long hashBytesIndirect(byte[] b) {
return getHasherInstance().hashToLong(b, BYTES_FUNNEL);
protected void hashBytesIndirect(byte[] b, Blackhole blackhole) {
blackhole.consume(getHasherInstance().hashToLong(b, BYTES_FUNNEL));
}

@Override
protected long hashCharsDirect(String s) {
return getHasherInstance().hashCharsToLong(s);
protected void hashCharsDirect(String s, Blackhole blackhole) {
blackhole.consume(getHasherInstance().hashCharsToLong(s));
}

@Override
protected long hashCharsIndirect(String s) {
return getHasherInstance().hashToLong(s, CHARS_FUNNEL);
protected void hashCharsIndirect(String s, Blackhole blackhole) {
blackhole.consume(getHasherInstance().hashToLong(s, CHARS_FUNNEL));
}

protected abstract Hasher64 getHasherInstance();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2022-2025 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;

import com.google.common.hash.Funnel;
import com.google.common.hash.HashFunction;
import org.openjdk.jmh.infra.Blackhole;

public abstract class AbstractGuava128BitPerformanceTest extends AbstractPerformanceTest {

protected static final Funnel<String> CHARS_FUNNEL = (s, sink) -> sink.putUnencodedChars(s);
protected static final Funnel<byte[]> BYTES_FUNNEL = (s, sink) -> sink.putBytes(s);

@Override
protected void hashObject(TestObject testObject, Blackhole blackhole) {
blackhole.consume(createHashFunction().hashObject(testObject, TestObject::contributeToHash));
}

@Override
protected void hashBytesDirect(byte[] b, Blackhole blackhole) {
blackhole.consume(createHashFunction().hashBytes(b));
}

@Override
protected void hashCharsDirect(String s, Blackhole blackhole) {
blackhole.consume(createHashFunction().hashUnencodedChars(s));
}

@Override
protected void hashCharsIndirect(String s, Blackhole blackhole) {
blackhole.consume(createHashFunction().hashObject(s, CHARS_FUNNEL));
}

@Override
protected void hashBytesIndirect(byte[] b, Blackhole blackhole) {
blackhole.consume(createHashFunction().hashObject(b, BYTES_FUNNEL));
}

protected abstract HashFunction createHashFunction();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,35 +17,37 @@

import com.google.common.hash.Funnel;
import com.google.common.hash.HashFunction;
import org.openjdk.jmh.infra.Blackhole;

public abstract class AbstractGuava32BitPerformanceTest extends AbstractPerformanceTest {

protected static final Funnel<String> CHARS_FUNNEL = (s, sink) -> sink.putUnencodedChars(s);
protected static final Funnel<byte[]> BYTES_FUNNEL = (s, sink) -> sink.putBytes(s);

@Override
protected long hashObject(TestObject testObject) {
return createHashFunction().hashObject(testObject, TestObject::contributeToHash).asInt();
protected void hashObject(TestObject testObject, Blackhole blackhole) {
blackhole.consume(
createHashFunction().hashObject(testObject, TestObject::contributeToHash).asInt());
}

@Override
protected long hashBytesDirect(byte[] b) {
return createHashFunction().hashBytes(b).asInt();
protected void hashBytesDirect(byte[] b, Blackhole blackhole) {
blackhole.consume(createHashFunction().hashBytes(b).asInt());
}

@Override
protected long hashCharsDirect(String s) {
return createHashFunction().hashUnencodedChars(s).asInt();
protected void hashCharsDirect(String s, Blackhole blackhole) {
blackhole.consume(createHashFunction().hashUnencodedChars(s).asInt());
}

@Override
protected long hashCharsIndirect(String s) {
return createHashFunction().hashObject(s, CHARS_FUNNEL).asInt();
protected void hashCharsIndirect(String s, Blackhole blackhole) {
blackhole.consume(createHashFunction().hashObject(s, CHARS_FUNNEL).asInt());
}

@Override
protected long hashBytesIndirect(byte[] b) {
return createHashFunction().hashObject(b, BYTES_FUNNEL).asInt();
protected void hashBytesIndirect(byte[] b, Blackhole blackhole) {
blackhole.consume(createHashFunction().hashObject(b, BYTES_FUNNEL).asInt());
}

protected abstract HashFunction createHashFunction();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,35 +17,37 @@

import com.google.common.hash.Funnel;
import com.google.common.hash.HashFunction;
import org.openjdk.jmh.infra.Blackhole;

public abstract class AbstractGuava64BitPerformanceTest extends AbstractPerformanceTest {

protected static final Funnel<String> CHARS_FUNNEL = (s, sink) -> sink.putUnencodedChars(s);
protected static final Funnel<byte[]> BYTES_FUNNEL = (s, sink) -> sink.putBytes(s);

@Override
protected long hashObject(TestObject testObject) {
return createHashFunction().hashObject(testObject, TestObject::contributeToHash).asLong();
protected void hashObject(TestObject testObject, Blackhole blackhole) {
blackhole.consume(
createHashFunction().hashObject(testObject, TestObject::contributeToHash).asLong());
}

@Override
protected long hashBytesDirect(byte[] b) {
return createHashFunction().hashBytes(b).asLong();
protected void hashBytesDirect(byte[] b, Blackhole blackhole) {
blackhole.consume(createHashFunction().hashBytes(b).asLong());
}

@Override
protected long hashCharsDirect(String s) {
return createHashFunction().hashUnencodedChars(s).asLong();
protected void hashCharsDirect(String s, Blackhole blackhole) {
blackhole.consume(createHashFunction().hashUnencodedChars(s).asLong());
}

@Override
protected long hashCharsIndirect(String s) {
return createHashFunction().hashObject(s, CHARS_FUNNEL).asLong();
protected void hashCharsIndirect(String s, Blackhole blackhole) {
blackhole.consume(createHashFunction().hashObject(s, CHARS_FUNNEL).asLong());
}

@Override
protected long hashBytesIndirect(byte[] b) {
return createHashFunction().hashObject(b, BYTES_FUNNEL).asLong();
protected void hashBytesIndirect(byte[] b, Blackhole blackhole) {
blackhole.consume(createHashFunction().hashObject(b, BYTES_FUNNEL).asLong());
}

protected abstract HashFunction createHashFunction();
Expand Down
Loading

0 comments on commit 6460821

Please sign in to comment.