You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Alex Herbert (Jira)" <ji...@apache.org> on 2019/11/21 14:17:00 UTC

[jira] [Updated] (CODEC-269) Allow repeat calls to IncrementalHash32.end() to generate the same value.

     [ https://issues.apache.org/jira/browse/CODEC-269?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alex Herbert updated CODEC-269:
-------------------------------
    Summary: Allow repeat calls to IncrementalHash32.end() to generate the same value.  (was: MurmurHash3.IncrementalHash32)

> Allow repeat calls to IncrementalHash32.end() to generate the same value.
> -------------------------------------------------------------------------
>
>                 Key: CODEC-269
>                 URL: https://issues.apache.org/jira/browse/CODEC-269
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.13
>            Reporter: Alex Herbert
>            Assignee: Alex Herbert
>            Priority: Trivial
>
> The MurmurHash3.IncrementalHash32 end() method alters the current state of the running hash. Thus if called twice it returns different numbers.
> This can be fixed using:
> {code:java}
> public final int end() {
>     // Allow calling end() again after adding no data to return the same result.
>     int result = hash;
>     // ************
>     // Note: This fails to apply masking using 0xff to the 3 remaining bytes.
>     // ************
>     int k1 = 0;
>     switch (unprocessedLength) {
>     case 3:
>         k1 ^= unprocessed[2] << 16;
>     case 2:
>         k1 ^= unprocessed[1] << 8;
>     case 1:
>         k1 ^= unprocessed[0];
>         // mix functions
>         k1 *= C1_32;
>         k1 = Integer.rotateLeft(k1, R1_32);
>         k1 *= C2_32;
>         result ^= k1;
>     }
>     // finalization
>     result ^= totalLen;
>     return fmix32(result);
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)