Skip to content

Commit

Permalink
Fix murmurhash2 when string length is a multiple of a 4
Browse files Browse the repository at this point in the history
The first h *= m after the loop should only happen for len % 4 != 0.
  • Loading branch information
michaelforney authored and Ori Bernstein committed Jul 18, 2017
1 parent aa40abd commit d664062
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 5 additions & 3 deletions lib/std/hashfuncs.myr
Expand Up @@ -121,17 +121,19 @@ const murmurhash2 = {data, seed
match data.len
| 3:
h ^= (data[2] : uint32) << 16
h ^= (data[1] : uint32) <<8
h ^= (data[1] : uint32) << 8
h ^= (data[0] : uint32)
h *= m
| 2:
h ^= (data[1] : uint32) <<8
h ^= (data[1] : uint32) << 8
h ^= (data[0] : uint32)
h *= m
| 1:
h ^= (data[0] : uint32)
h *= m
| 0: /* nothing */
| _: die("0 < len < 4 must be true")
;;
h *= m

h ^= h >> 13
h *= m
Expand Down
6 changes: 2 additions & 4 deletions util/htab.c
Expand Up @@ -322,10 +322,8 @@ murmurhash2 (void *ptr, size_t len)
case 3: h ^= p[2] << 16;
case 2: h ^= p[1] << 8;
case 1: h ^= p[0] << 0;
default:
break;
};
h *= m;
h *= m;
}

h ^= h >> 13;
h *= m;
Expand Down

0 comments on commit d664062

Please sign in to comment.