Method: List#&

Defined in:
ext/list/list.c

#&(list2) ⇒ Object



2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
# File 'ext/list/list.c', line 2080

static VALUE
list_and(VALUE list1, VALUE list2)
{
  VALUE list3, hash;
  st_table *table;
  st_data_t vv;
  item_t *c1;

  list2 = to_list(list2);
  list3 = list_new();
  if (LIST_LEN(list2) == 0) return list3;
  hash = list_make_hash(list2);
  table = RHASH_TBL(hash);

  LIST_FOR(list1, c1) {
    vv = (st_data_t) c1->value;
    if (st_delete(table, &vv, 0)) {
      list_push(list3, c1->value);
    }
  }

  return list3;
}