Le 29 déc. 2013 à 12:50, Asis Hallab <asis.hal...@gmail.com> a écrit :
> Dear Rcpp experst, > > I hope everyone has had a pleasant Xmas. > > I am just wondering what would be the recommended and most efficient way to > check, if a Rcpp Vector contains a given element? > > If I am not mistaken the C++ standard approach for very large std::vectors > would be to first sort them and then perform a binary search: > > http://stackoverflow.com/questions/571394/how-to-find-an-item-in-a-stdvector I believe you are mistaken. sorting is an expensive O( N log(N) ) operation. I’d use something like std::find (or std::any_of if you use C++11). Those are O(N) Otherwise, you might like Rcpp::any or Rcpp::any_of Romain > What would be the Rcpp solution for the same task on a Rcpp vector? > Should I convert my Rcpp Vector to a std::vector and do the above, as > explained on the stackoverflow blog? > > Cheers and a happy new year!
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel