Created
August 28, 2012 09:17
-
-
Save tpeng/3496464 to your computer and use it in GitHub Desktop.
A simple minhash implementation in Java.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.common.hash.HashFunction; | |
import com.google.common.hash.Hashing; | |
/** | |
* A simple MinHash implementation inspired by https://github.com/jmhodges/minhash | |
* | |
* @author tpeng ([email protected]) | |
*/ | |
public class MinHash { | |
private HashFunction hash = Hashing.murmur3_32(); | |
public String hash(String string) { | |
int min = Integer.MAX_VALUE; | |
for (int i=0; i<string.length(); i++) { | |
int c = string.charAt(i); | |
int n = hash.hashInt(c).asInt(); | |
if (n < min) { | |
min = n; | |
} | |
} | |
return Integer.toHexString(min); | |
} | |
public static void main(String... args) { | |
MinHash minHash = new MinHash(); | |
System.out.println(minHash.hash("abc")); | |
System.out.println(minHash.hash("abcd")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment