public Method

Array.hash

array.hash    fixnum

Compute a hash-code for this array. Two arrays with the same content will have the same hash code (and will compare using eql?).

Source Code

/*
*  call-seq:
*     array.hash   -> fixnum
*
*  Compute a hash-code for this array. Two arrays with the same content
*  will have the same hash code (and will compare using <code>eql?</code>).
*/

static VALUE
rb_ary_hash(ary)
   VALUE ary;
{
   long i, h;
   VALUE n;

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

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.