Created
August 18, 2013 12:33
-
-
Save komiya-atsushi/6261436 to your computer and use it in GitHub Desktop.
4 バイトリトルエンディアンなデータに対して xxHash ( https://code.google.com/p/xxhash/ ) のハッシュ値を計算するコード。ループその他諸々を取っ払って実装したので、(利用ケースは限定的になるけど)速いはず。
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
public class XXHash { | |
private static final int PRIME32_2 = (int) 2246822519L; | |
private static final int PRIME32_3 = (int) 3266489917L; | |
private static final int PRIME32_4 = 668265263; | |
private static final int PRIME32_5 = 374761393; | |
public static int xxHash4ByteLE(int val, int seed) { | |
long h32 = seed + PRIME32_5 + 4; | |
h32 += (val & 0xffffffffL) * PRIME32_3; | |
h32 &= 0xffffffffL; | |
h32 = (((h32 << 17) & 0xffffffffL) | (h32 >>> (32 - 17))) * PRIME32_4; | |
h32 &= 0xffffffffL; | |
h32 ^= h32 >>> 15; | |
h32 *= PRIME32_2; | |
h32 &= 0xffffffffL; | |
h32 ^= h32 >>> 13; | |
h32 *= PRIME32_3; | |
h32 &= 0xffffffffL; | |
h32 ^= h32 >>> 16; | |
return (int) h32; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment