uniq!()
public
Removes duplicate elements from self. Returns nil if no
changes are made (that is, no duplicates are found).
a = [ "a", "a", "b", "b", "c" ]
a.uniq!
b = [ "a", "b", "c" ]
b.uniq!
Show source
/*
* call-seq:
* array.uniq! -> array or nil
*
* Removes duplicate elements from _self_.
* Returns <code>nil</code> if no changes are made (that is, no
* duplicates are found).
*
* a = [ "a", "a", "b", "b", "c" ]
* a.uniq!
* b = [ "a", "b", "c" ]
* b.uniq!
*/
static VALUE
rb_ary_uniq_bang(ary)
VALUE ary;
{
VALUE hash, v, vv;
long i, j;
hash = ary_make_hash(ary, 0);
if (RARRAY(ary)->len == RHASH(hash)->tbl->num_entries) {
return Qnil;
}
for (i=j=0; i<RARRAY(ary)->len; i++) {
v = vv = rb_ary_elt(ary, i);
if (st_delete(RHASH(hash)->tbl, (st_data_t*)&vv, 0)) {
rb_ary_store(ary, j++, v);
}
}
RARRAY(ary)->len = j;
return ary;
}