Skip to content

Instantly share code, notes, and snippets.

@hadley
Created November 16, 2012 16:41
Show Gist options
  • Select an option

  • Save hadley/4088816 to your computer and use it in GitHub Desktop.

Select an option

Save hadley/4088816 to your computer and use it in GitHub Desktop.
// [[Rcpp::export]]
LogicalVector duplicated3(IntegerVector x) {
std::set<int> seen;
LogicalVector out(x.size());
IntegerVector::iterator it, end = x.end();
LogicalVector::iterator out_it;
for (it = x.begin(), out_it = out.begin(); it != end; ++it, ++out_it) {
*out_it = seen.insert(*it).second;
}
return(out);
}
// [[Rcpp::export]]
LogicalVector duplicated4(IntegerVector x) {
std::set<int> seen;
int n = x.size();
LogicalVector out(n);
for (int i = 0; i < n; ++i) {
out[i] = seen.insert(x[i]).second;
}
return(out);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment