&(p1)
public
Set Intersection—Returns a new array containing elements common to
the two arrays, with no duplicates.
[ 1, 1, 3, 5 ] & [ 1, 2, 3 ]
Show source
static VALUE
rb_ary_and(VALUE ary1, VALUE ary2)
{
VALUE hash, ary3, v, vv;
long i;
ary2 = to_ary(ary2);
ary3 = rb_ary_new2(RARRAY_LEN(ary1) < RARRAY_LEN(ary2) ?
RARRAY_LEN(ary1) : RARRAY_LEN(ary2));
hash = ary_make_hash(ary2, 0);
if (RHASH_EMPTY_P(hash))
return ary3;
for (i=0; i<RARRAY_LEN(ary1); i++) {
v = vv = rb_ary_elt(ary1, i);
if (st_delete(RHASH_TBL(hash), (st_data_t*)&vv, 0)) {
rb_ary_push(ary3, v);
}
}
return ary3;
}