Module: RumourHash

Defined in:
lib/antlr4/runtime.rb,
ext/rumourhash/rumourhash.c

Instance Method Summary collapse

Instance Method Details

#bit_count(v) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
51
# File 'ext/rumourhash/rumourhash.c', line 40

static VALUE bit_count(VALUE self, VALUE v) {
    long num = NUM2LONG(v);
    int count = 0;

    while (num)
    {
      num &= (num-1) ;
      count++;
    }

    return INT2NUM(count);
}

#rumour_hash_finish(hashv, n_wordsv) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'ext/rumourhash/rumourhash.c', line 26

static VALUE rumour_hash_finish(VALUE self, VALUE hashv, VALUE n_wordsv) {
    long hash = NUM2LONG(hashv);
    long n_words = NUM2LONG(n_wordsv);

    hash = hash ^ (n_words * 4);
    hash = hash ^ (hash >> 16);
    hash *= 0x85EBCA6B;
    hash = hash ^ (hash >> 13);
    hash *= 0xC2B2AE35;
    hash ^= (hash >> 16);

    return LONG2NUM(hash);
}

#rumour_hash_update_int(hashv, valuev) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'ext/rumourhash/rumourhash.c', line 10

static VALUE rumour_hash_update_int(VALUE self, VALUE hashv, VALUE valuev) {
    long hash = NUM2LONG(hashv);
    long value = NUM2LONG(valuev);

    long k = value;
    k *= c1;
    k = (k << r1) | (k >> (32 - r1));
    k *= c2;

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

    return LONG2NUM(hash);
}