module RumourHash

Public Class Methods

bit_count(p1) click to toggle source
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(p1, p2 = v2) click to toggle source
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(p1, p2) click to toggle source
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(p1, p2) click to toggle source
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);
}