/*
 * call-seq:
 *   struct.hash   => fixnum
 *
 * Return a hash value based on this struct's contents.
 */

static VALUE
rb_struct_hash(VALUE s)
{
    long i, h;
    VALUE n;

    h = rb_hash(rb_obj_class(s));
    for (i = 0; i < RSTRUCT_LEN(s); i++) {
        h = (h << 1) | (h<0 ? 1 : 0);
        n = rb_hash(RSTRUCT_PTR(s)[i]);
        h ^= NUM2LONG(n);
    }
    return LONG2FIX(h);
}