Advertisement
Guest User

Untitled

a guest
Jul 29th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. static VALUE
  2. rb_ary_and(VALUE ary1, VALUE ary2)
  3. {
  4. VALUE hash, ary3, v;
  5. st_data_t vv;
  6. long i;
  7.  
  8. ary2 = to_ary(ary2);
  9. ary3 = rb_ary_new2(RARRAY_LEN(ary1) < RARRAY_LEN(ary2) ?
  10. RARRAY_LEN(ary1) : RARRAY_LEN(ary2));
  11. hash = ary_make_hash(ary2);
  12.  
  13. if (RHASH_EMPTY_P(hash))
  14. return ary3;
  15.  
  16. for (i=0; i<RARRAY_LEN(ary1); i++) {
  17. vv = (st_data_t)(v = rb_ary_elt(ary1, i));
  18. if (st_delete(RHASH_TBL(hash), &vv, 0)) {
  19. rb_ary_push(ary3, v);
  20. }
  21. }
  22. ary_recycle_hash(hash);
  23.  
  24. return ary3;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement