ref: d66406270f0743f0713c35cdcc8f371b58a50004
parent: aa40abd25de6fc94621a41b360b5808b3aa57b55
author: Michael Forney <mforney@mforney.org>
date: Mon Jul 17 23:53:50 EDT 2017
Fix murmurhash2 when string length is a multiple of a 4 The first h *= m after the loop should only happen for len % 4 != 0.
--- a/lib/std/hashfuncs.myr
+++ b/lib/std/hashfuncs.myr
@@ -121,17 +121,19 @@
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
--- a/util/htab.c
+++ b/util/htab.c
@@ -322,10 +322,8 @@
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;