Skip to content

Commit

Permalink
basic implementation of PolymurHash 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
oertl committed Jun 26, 2023
1 parent 42abdf9 commit b75a069
Show file tree
Hide file tree
Showing 9 changed files with 14,848 additions and 14 deletions.
2 changes: 1 addition & 1 deletion licenses/ZLIB_POLYMURHASH.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ the following restrictions:
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.

3. This notice may not be removed or altered from any source distribution.
3. This notice may not be removed or altered from any source distribution.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ void PolymurHash_2_0_ChecksumConfig::calculateHash(const uint8_t *seedBytes,
uint64_t seed0;
uint64_t seed1;
uint64_t tweak;
memcpy(&seed0, seedBytes, 8);
memcpy(&seed1, seedBytes + 8, 8);
memcpy(&tweak, seedBytes + 16, 8);
memcpy(&tweak, seedBytes, 8);
memcpy(&seed0, seedBytes + 8, 8);
memcpy(&seed1, seedBytes + 16, 8);
PolymurHashParams params0;
PolymurHashParams params1;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.
* 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 PolymurHash2_0PerformanceTest extends AbstactHasher64PerformanceTest {

private static final Hasher64 HASHER_INSTANCE =
Hashing.polymurHash2_0(0x2afe2c5c76d4017eL, 0x46223142eceb1893L);

@Override
protected Hasher64 getHasherInstance() {
return HASHER_INSTANCE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,5 @@ public long getAsLong() {

return finalizeGetAsLong(se1, se5, off, len);
}

@Override
public int getHashBitSize() {
return 64;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,5 @@ public long getAsLong() {
}
return finish(a, b, s, byteCount);
}

@Override
public int getHashBitSize() {
return 64;
}
}
}
35 changes: 35 additions & 0 deletions src/main/java/com/dynatrace/hash4j/hashing/Hashing.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,41 @@ public static Hasher64 komihash5_0(long seed) {
return Komihash5_0.create(seed);
}

/**
* Returns a {@link Hasher64} implementing the 64-bit PolymurHash (version 2.0) algorithm using
* the given tweak and seed value.
*
* <p>This implementation is compatible with the C++ reference implementation of {@code
* polymur_hash} defined in <a
* href="https://github.com/orlp/polymur-hash/blob/c6cc6884459560443e696604e9db3b6bb61a9bfa/polymur-hash.h">polymur-hash.h</a>
* on an Intel x86 architecture.
*
* @param tweak a 64-bit tweak
* @param seed a 64-bit seed
* @return a hasher instance
*/
public static Hasher64 polymurHash2_0(long tweak, long seed) {
return PolymurHash2_0.create(tweak, seed);
}

/**
* Returns a {@link Hasher64} implementing the 64-bit PolymurHash (version 2.0) algorithm using
* the given tweak and seed values.
*
* <p>This implementation is compatible with the C++ reference implementation of {@code
* polymur_hash} defined in <a
* href="https://github.com/orlp/polymur-hash/blob/c6cc6884459560443e696604e9db3b6bb61a9bfa/polymur-hash.h">polymur-hash.h</a>
* on an Intel x86 architecture.
*
* @param tweak a 64-bit tweak
* @param kSeed a 64-bit kSeed
* @param sSeed a 64-bit kSeed
* @return a hasher instance
*/
public static Hasher64 polymurHash2_0(long tweak, long kSeed, long sSeed) {
return PolymurHash2_0.create(tweak, kSeed, sSeed);
}

/**
* Returns a {@link Hasher64} implementing the 64-bit Wyhash (version final 3) algorithm using a
* seed value of zero and the default secret.
Expand Down
Loading

0 comments on commit b75a069

Please sign in to comment.