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

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

    h = rb_hash(rb_obj_class(s));
    for (i = 0; i < RSTRUCT(s)->len; i++) {
        h = (h << 1) | (h<0 ? 1 : 0);
        n = rb_hash(RSTRUCT(s)->ptr[i]);
        h ^= NUM2LONG(n);
    }
    return LONG2FIX(h);
}