aherbert commented on a change in pull request #27: Murmur3fix
URL: https://github.com/apache/commons-codec/pull/27#discussion_r341853359
##########
File path: src/main/java/org/apache/commons/codec/digest/MurmurHash3.java
##########
@@ -602,15 +613,19 @@ public final void add(final byte[] data, int offset,
final int length) {
System.arraycopy(data, offset + consumed, tail, 0,
tailLen);
}
+ /*
+ * The original algorithm uses unsigned bytes.
+ * We have to mask to match the behavior of the unsigned bytes and
prevent sign extension.
+ */
public final int end() {
int k1 = 0;
switch (tailLen) {
case 3:
- k1 ^= tail[2] << 16;
+ k1 ^= (tail[2] & UBYTE_MASK) << 16;
Review comment:
In the change to `hash32` you switched to using `|=` operators from `^=` but
not here.
In both cases it makes no difference as k1 is zero and `^=` will produce the
equivalent. I suggest changing the `|=` operator back to `^=`. This will
minimise the changes in the PR.
A performance test against an updated algorithm that exclusively uses `|=`
would justify a change. Otherwise just leave it as is. I'd expect no difference
anyway given this is in the `end()` method and will be a minority of the
runtime for the overall hash method.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services