[Rcpp-commits] r4074 - in pkg/Rcpp: . inst inst/include/Rcpp/hash inst/include/Rcpp/sugar/functions
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Dec 4 16:59:15 CET 2012
Author: romain
Date: 2012-12-04 16:59:15 +0100 (Tue, 04 Dec 2012)
New Revision: 4074
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/NEWS.Rd
pkg/Rcpp/inst/include/Rcpp/hash/hash.h
pkg/Rcpp/inst/include/Rcpp/sugar/functions/unique.h
Log:
more efficient version of in
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2012-12-04 15:35:33 UTC (rev 4073)
+++ pkg/Rcpp/ChangeLog 2012-12-04 15:59:15 UTC (rev 4074)
@@ -12,7 +12,10 @@
* include/Rcpp/hash/hash.h: new implementation of IndexHash, based on
Simon's fastmatch package
- * include/Rcpp/sugar/functions/match.h: using new IndexHash
+ * include/Rcpp/sugar/functions/match.h: more efficient version of match
+ using new IndexHash
+ * include/Rcpp/sugar/functions/unique.h: more efficient version of
+ unique and in using IndexHash
* include/Rcpp/vector/Vector.h: more efficiently create Vector from
sugar expression that are already vectors, i.e. grab the SEXP
Modified: pkg/Rcpp/inst/NEWS.Rd
===================================================================
--- pkg/Rcpp/inst/NEWS.Rd 2012-12-04 15:35:33 UTC (rev 4073)
+++ pkg/Rcpp/inst/NEWS.Rd 2012-12-04 15:59:15 UTC (rev 4074)
@@ -19,6 +19,7 @@
\itemize{
\item More efficient version of \code{match} based on \code{IndexHash}
\item More efficient version of \code{unique} base on \code{IndexHash}
+ \item More efficient version of \code{in} base on \code{IndexHash}
}
}
}
Modified: pkg/Rcpp/inst/include/Rcpp/hash/hash.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/hash/hash.h 2012-12-04 15:35:33 UTC (rev 4073)
+++ pkg/Rcpp/inst/include/Rcpp/hash/hash.h 2012-12-04 15:59:15 UTC (rev 4074)
@@ -55,8 +55,8 @@
return lookup__impl(vec.begin(), vec.size() ) ;
}
- bool contains(STORAGE val) const {
- return get_index(val) == NA_INTEGER ;
+ inline bool contains(STORAGE val) const {
+ return get_index(val) != NA_INTEGER ;
}
inline int size() const {
Modified: pkg/Rcpp/inst/include/Rcpp/sugar/functions/unique.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/unique.h 2012-12-04 15:35:33 UTC (rev 4073)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/unique.h 2012-12-04 15:59:15 UTC (rev 4074)
@@ -25,35 +25,35 @@
namespace Rcpp{
namespace sugar{
-template <typename SET, typename STORAGE>
+template <typename HASH>
class InSet {
+ typedef typename HASH::STORAGE STORAGE ;
+
public:
- InSet( const SET& hash_ ) : hash(hash_), end(hash_.end()){}
+ InSet( const HASH& hash_ ) : hash(hash_){}
inline int operator()(STORAGE value){
- return hash.find(value) != end ;
+ return hash.contains(value) ;
}
private:
- const SET& hash ;
- typename SET::const_iterator end ;
+ const HASH& hash ;
} ;
template <int RTYPE, typename TABLE_T>
class In {
+ Vector<RTYPE> vec ;
+ typedef sugar::IndexHash<RTYPE> HASH ;
+ HASH hash ;
+
public:
- In( const TABLE_T& table) : hash( get_const_begin(table), get_const_end(table) ){}
+ In( const TABLE_T& table) : vec(table), hash(vec){}
template <typename T>
LogicalVector get( const T& x) const {
- return LogicalVector( x.begin(), x.end(), InSet<SET,STORAGE>(hash) ) ;
+ return LogicalVector( x.begin(), x.end(), InSet<HASH>(hash) ) ;
}
-
-private:
- typedef typename traits::storage_type<RTYPE>::type STORAGE ;
- typedef typename RCPP_UNORDERED_SET<STORAGE> SET ;
- SET hash ;
-
+
} ;
@@ -72,8 +72,8 @@
template <int RTYPE, bool NA, typename T, bool RHS_NA, typename RHS_T>
inline LogicalVector in( const VectorBase<RTYPE,NA,T>& x, const VectorBase<RTYPE,RHS_NA,RHS_T>& table ){
- sugar::In<RTYPE,RHS_T> obj(table.get_ref()) ;
- return obj.get( x.get_ref() );
+ typedef VectorBase<RTYPE,RHS_NA,RHS_T> TABLE_T ;
+ return sugar::In<RTYPE, TABLE_T>(table).get( x.get_ref() ) ;
}
More information about the Rcpp-commits
mailing list