Module: RumourHash
- Defined in:
- lib/antlr4/runtime.rb,
ext/rumourhash/rumourhash.c
Class Method Summary collapse
- .bit_count(v) ⇒ Object
- .calculate(*args) ⇒ Object
- .finish(hashv, n_wordsv) ⇒ Object
- .update_int(hashv, valuev) ⇒ Object
Class Method Details
.bit_count(v) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'ext/rumourhash/rumourhash.c', line 85
static VALUE rumour_hash_bit_count(VALUE self, VALUE v) {
long num = NUM2LONG(v);
int count = 0;
while (num)
{
num &= (num-1) ;
count++;
}
return INT2NUM(count);
}
|
.calculate(*args) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'ext/rumourhash/rumourhash.c', line 49
static VALUE rumour_hash_calculate(int argc, VALUE* argv, VALUE self) {
VALUE itemsv;
VALUE seed;
rb_scan_args(argc, argv, "11", &itemsv, &seed);
long hash;
if (seed == Qnil) {
hash = defaultSeed;
} else {
hash = NUM2LONG(seed);
}
int i;
for (i = 0; i < RARRAY_LEN(itemsv); i ++) {
VALUE current = RARRAY_AREF(itemsv, i);
long val;
if (current == Qnil || current == Qfalse) {
val = 0;
} else if (current == Qtrue) {
val = 1;
} else if (CLASS_OF(current) == rb_cInteger) {
val = NUM2LONG(current);
} else {
val = NUM2LONG(rb_hash(current));
}
hash = rumour_hash_update_int_impl(self, hash, val);
}
hash = rumour_hash_finish_impl(self, hash, RARRAY_LEN(itemsv));
return LONG2NUM(hash);
}
|
.finish(hashv, n_wordsv) ⇒ Object
42 43 44 45 46 47 |
# File 'ext/rumourhash/rumourhash.c', line 42
static VALUE rumour_hash_finish(VALUE self, VALUE hashv, VALUE n_wordsv) {
long hash = NUM2LONG(hashv);
long n_words = NUM2LONG(n_wordsv);
hash = rumour_hash_finish_impl(self, hash, n_words);
return LONG2NUM(hash);
}
|
.update_int(hashv, valuev) ⇒ Object
24 25 26 27 28 29 |
# File 'ext/rumourhash/rumourhash.c', line 24
static VALUE rumour_hash_update_int(VALUE self, VALUE hashv, VALUE valuev) {
long hash = NUM2LONG(hashv);
long value = NUM2LONG(valuev);
hash = rumour_hash_update_int_impl(self, hash, value);
return LONG2NUM(hash);
}
|