Skip to content

Commit

Permalink
Updated murmurhash3_gc.js to final version of MurmurHash3.
Browse files Browse the repository at this point in the history
MurmurHash3 was updated and declared final on April 2,
2011 (http://code.google.com/p/smhasher/). This patch reflects those
changes.
  • Loading branch information
TimDumol committed Apr 6, 2011
1 parent 16e33ad commit 917f022
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions murmurhash3_gc.js
Expand Up @@ -14,11 +14,11 @@
function murmurhash3_32_gc(key, seed) {
var remainder, bytes, h1, h1b, c1, c1b, c2, c2b, k1, i;

remainder = key.length % 4;
remainder = key.length & 3; // key.length % 4
bytes = key.length - remainder;
h1 = 0x971e137b ^ seed;
c1 = 0x95543787;
c2 = 0x2ad7eb25;
h1 = seed;
c1 = 0xcc9e2d51;
c2 = 0x1b873593;
i = 0;

while (i < bytes) {
Expand All @@ -30,17 +30,13 @@ function murmurhash3_32_gc(key, seed) {
++i;

k1 = (((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16));
k1 = (k1 << 11) | (k1 >>> 21);
k1 = (k1 << 15) | (k1 >>> 17);
k1 = (((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16));

h1 ^= k1;

h1b = (((h1 & 0xffff) * 3) + ((((h1 >>> 16) * 3) & 0xffff) << 16));
h1 = (((h1b & 0xffff) + 0xe729) + ((((h1b >>> 16) + 0x52dc) & 0xffff) << 16));

c1b = (((c1 & 0xffff) * 5) + ((((c1 >>> 16) * 5) & 0xffff) << 16));
c1 = (((c1b & 0xffff) + 0x159c) + ((((c1b >>> 16) + 0x7b7d) & 0xffff) << 16));
c2b = (((c2 & 0xffff) * 5) + ((((c2 >>> 16) * 5) & 0xffff) << 16));
c2 = (((c2b & 0xffff) + 0x6396) + ((((c2b >>> 16) + 0x6bce) & 0xffff) << 16));
h1 = (h1 << 13) | (h1 >>> 19);
h1b = (((h1 & 0xffff) * 5) + ((((h1 >>> 16) * 5) & 0xffff) << 16));
h1 = (((h1b & 0xffff) + 0x6b64) + ((((h1b >>> 16) + 0xe654) & 0xffff) << 16));
}

k1 = 0;
Expand All @@ -51,12 +47,9 @@ function murmurhash3_32_gc(key, seed) {
case 1: k1 ^= (key.charCodeAt(i) & 0xff);

k1 = (((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16));
k1 = (k1 << 11) | (k1 >>> 21);
k1 = (k1 << 16) | (k1 >>> 26);
k1 = (((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16));
h1 ^= k1;

h1b = (((h1 & 0xffff) * 3) + ((((h1 >>> 16) * 3) & 0xffff) << 16));
h1 = (((h1b & 0xffff) + 0xe729) + ((((h1b >>> 16) + 0x52dc) & 0xffff) << 16));
}

h1 ^= key.length;
Expand Down

0 comments on commit 917f022

Please sign in to comment.