Skip to content

Instantly share code, notes, and snippets.

@benaskins
Created December 11, 2008 07:07
Show Gist options
  • Save benaskins/34628 to your computer and use it in GitHub Desktop.
Save benaskins/34628 to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment