Method: ValueSet#intersection!

Defined in:
ext/value_set.cc

#intersection!(other) ⇒ Object

Computes the intersection of set and other, and modifies self to be that interesection. This operation is O(N + M) if other is a ValueSet



174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'ext/value_set.cc', line 174

static VALUE value_set_intersection_bang(VALUE vself, VALUE vother)
{
    ValueSet& self  = get_wrapped_set(vself);
    if (!RTEST(rb_obj_is_kind_of(vother, cValueSet)))
	rb_raise(rb_eArgError, "expected a ValueSet");
    ValueSet const& other = get_wrapped_set(vother);
    
    ValueSet result;
    std::set_intersection(self.begin(), self.end(), other.begin(), other.end(), 
	    std::inserter(result, result.end()));
    self.swap(result);
    return vself;
}