Module: Fairy::SimpleHash

Defined in:
ext/simple_hash/simple_hash.c

Class Method Summary collapse

Class Method Details

.hash(vstr) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'ext/simple_hash/simple_hash.c', line 16

static VALUE simple_hash(VALUE self, VALUE vstr) {
    VALUE vh;
    char *str;
    int len;
    char *p;
    unsigned int h = 0;

    str = StringValuePtr(vstr);
    len = RSTRING_LEN(vstr);

    for (p = str; p - str < len; p++) {
        h = h * MULTIPLIER + *p;
    }

    /* vh = UINT2NUM(h); */
    vh = INT2FIX(h);
    return vh;
}