Search
 
SCRIPT & CODE EXAMPLE
 

BASIC

basic murmur hash function

uint32_t murmur3_32(const char *key, uint32_t len, uint32_t seed) {
    static const uint32_t c1 = 0xcc9e2d51;
    static const uint32_t c2 = 0x1b873593;
    static const uint32_t r1 = 15;
    static const uint32_t r2 = 13;
    static const uint32_t m = 5;
    static const uint32_t n = 0xe6546b64;

    uint32_t hash = seed;

    const int nblocks = len / 4;
    const uint32_t *blocks = (const uint32_t *) key;
    int i;
    for (i = 0; i < nblocks; i++) {
        uint32_t k = blocks[i];
        k *= c1;
        k = (k << r1) | (k >> (32 - r1));
        k *= c2;

        hash ^= k;
        hash = ((hash << r2) | (hash >> (32 - r2))) * m + n;
    }

    const uint8_t *tail = (const uint8_t *) (key + nblocks * 4);
    uint32_t k1 = 0;

    switch (len & 3) {
    case 3:
        k1 ^= tail[2] << 16;
    case 2:
        k1 ^= tail[1] << 8;
    case 1:
        k1 ^= tail[0];

        k1 *= c1;
        k1 = (k1 << r1) | (k1 >> (32 - r1));
        k1 *= c2;
        hash ^= k1;
    }

    hash ^= len;
    hash ^= (hash >> 16);
    hash *= 0x85ebca6b;
    hash ^= (hash >> 13);
    hash *= 0xc2b2ae35;
    hash ^= (hash >> 16);

    return hash;
}
Comment

PREVIOUS NEXT
Code Example
Basic :: how to simulate tail in dos/cmd without tail 
Basic :: visual basic how to dynamically change a button to bold 
Elixir :: elixir debug 
Elixir :: elixir try rescue 
Elixir :: elixir ecto query to sql 
Elixir :: elixir datetime to timestamp 
Elixir :: phoenix query get first record 
Elixir :: elixir sleep 
Elixir :: elixir new structs 
Scala :: scala schemaPayload json 
Scala :: foreach batch spark scala 
Scala :: scala yield how to share one loop 
Scala :: currying scala 
Actionscript :: mount_osxfuse : Input/output error 
Excel :: google sheets count dates that fall within date range 
Excel :: freeze row in excel 
Perl :: perl $ @ % 
Pascal :: take console input in pascal 
Pascal :: pascal 
Powershell :: Auto-open DevTools on every new tab For powershell on Windows 
Clojure :: what is var in Clojure 
Erlang :: get erlang version 
Assembly :: resize pdf file 
Assembly :: nano error reading lock file not enough data read 
Javascript :: jquery vslidation remove spaces from input 
Javascript :: jquery remove required attribute 
Javascript :: react refresh page 
Javascript :: javascript void(0) href 
Javascript :: get tomorrows date using moment 
Javascript :: random number between 0 and 3 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =