Created
November 16, 2012 16:41
-
-
Save hadley/4088816 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // [[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