Skip to content

Commit

Permalink
Implement MurmurHash3
Browse files Browse the repository at this point in the history
  • Loading branch information
kusalk committed Dec 24, 2024
1 parent a9f037d commit acfa2ef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 7 additions & 1 deletion scavenger-model/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import com.google.protobuf.gradle.*
import com.google.protobuf.gradle.builtins
import com.google.protobuf.gradle.generateProtoTasks
import com.google.protobuf.gradle.id
import com.google.protobuf.gradle.plugins
import com.google.protobuf.gradle.protobuf
import com.google.protobuf.gradle.protoc

plugins {
java
Expand All @@ -17,6 +22,7 @@ dependencies {
implementation("io.grpc:grpc-kotlin-stub:${property("grpcKotlinVersion")}")
implementation("io.grpc:grpc-protobuf:${property("grpcVersion")}")
implementation("javax.annotation:javax.annotation-api:1.3.2")
implementation("commons-codec:commons-codec:1.17.1")
}

kotlin {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.navercorp.scavenger.util;

import org.apache.commons.codec.digest.MurmurHash3;

import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
Expand All @@ -9,7 +11,14 @@ public class HashGenerator {

public static class DefaultHash {
public static String from(String signature) {
return Md5.from(signature);
return Murmur.from(signature);
}
}

private static class Murmur {
private static String from(String signature) {
long[] x64hash = MurmurHash3.hash128x64(signature.getBytes(StandardCharsets.UTF_8));
return Long.toHexString(x64hash[0]) + Long.toHexString(x64hash[1]);
}
}

Expand Down

0 comments on commit acfa2ef

Please sign in to comment.