[Rcpp-commits] r4025 - in pkg/Rcpp: . inst inst/include/Rcpp/sugar/functions

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Nov 23 00:39:53 CET 2012


Author: romain
Date: 2012-11-23 00:39:53 +0100 (Fri, 23 Nov 2012)
New Revision: 4025

Added:
   pkg/Rcpp/inst/include/Rcpp/sugar/functions/duplicated.h
Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/NEWS.Rd
   pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h
Log:
duplicated

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-11-22 23:17:52 UTC (rev 4024)
+++ pkg/Rcpp/ChangeLog	2012-11-22 23:39:53 UTC (rev 4025)
@@ -6,6 +6,7 @@
         * src/coerce.cpp: added coercion to STRSXP
         * include/Rcpp/internal/r_coerce.h : added r_coerce<.,STRPSXP>
         * include/Rcpp/sugar/functions/table.h: sugar table
+        * include/Rcpp/sugar/functions/duplicated.h: sugar duplicated
         
 2012-11-21  JJ Allaire <jj at rstudio.org>
 

Modified: pkg/Rcpp/inst/NEWS.Rd
===================================================================
--- pkg/Rcpp/inst/NEWS.Rd	2012-11-22 23:17:52 UTC (rev 4024)
+++ pkg/Rcpp/inst/NEWS.Rd	2012-11-22 23:39:53 UTC (rev 4025)
@@ -8,9 +8,11 @@
         \itemize{
           \item New functions: \code{setdiff}, \code{union_}, \code{intersect}
             \code{setequal}, \code{in}, \code{min}, \code{max}, \code{range}, 
-            \code{match}
+            \code{match}, \code{table}, \code{duplicated}
           \item New function: \code{clip} which combines pmin and pmax, e.g. 
           clip( a, x, b) is the same as pmax( b, pmin(x, a) )
+          \item New function: \code{self_match} which implements something 
+          similar to \code{match( x, unique( x ) )}
         }
         \item Changes in Rcpp API:
         \itemize{

Added: pkg/Rcpp/inst/include/Rcpp/sugar/functions/duplicated.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/duplicated.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/duplicated.h	2012-11-22 23:39:53 UTC (rev 4025)
@@ -0,0 +1,71 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// duplicated.h: Rcpp R/C++ interface class library -- duplicated
+//
+// Copyright (C) 2012   Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef Rcpp__sugar__duplicated_h
+#define Rcpp__sugar__duplicated_h
+          
+namespace Rcpp{
+namespace sugar{
+
+template <typename SET, typename STORAGE>
+class DuplicatedInserter {
+public:
+    DuplicatedInserter( SET& set_ ) : set(set_) {}
+    
+    inline int operator()( STORAGE value ){
+        if( set.count(value) ) return TRUE ;
+        set.insert(value);
+        return FALSE ;
+    }
+    
+private:
+    SET& set ;
+} ; 
+
+template <int RTYPE, typename TABLE_T>        
+class Duplicated {
+public:
+    typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
+    
+    Duplicated( const TABLE_T& table ): set(), result(table.size()) {
+        std::transform( table.begin(), table.end(), result.begin(), Inserter(set) ) ;
+    }
+    
+    inline operator LogicalVector() const { return result ; }
+    
+private:
+    typedef RCPP_UNORDERED_SET<STORAGE> SET ;
+    typedef DuplicatedInserter<SET,STORAGE> Inserter ;
+    SET set ; 
+    LogicalVector result ;
+}; 
+  
+} // sugar
+
+template <int RTYPE, bool NA, typename T>
+inline LogicalVector duplicated( const VectorBase<RTYPE,NA,T>& x ){
+    return sugar::Duplicated<RTYPE,T>(x.get_ref()) ;
+}
+
+
+} // Rcpp
+#endif
+

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h	2012-11-22 23:17:52 UTC (rev 4024)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h	2012-11-22 23:39:53 UTC (rev 4025)
@@ -64,6 +64,7 @@
 #include <Rcpp/sugar/functions/unique.h>
 #include <Rcpp/sugar/functions/match.h>
 #include <Rcpp/sugar/functions/table.h>
+#include <Rcpp/sugar/functions/duplicated.h>
 #include <Rcpp/sugar/functions/self_match.h>
 #include <Rcpp/sugar/functions/setdiff.h>
 



More information about the Rcpp-commits mailing list