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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Dec 3 15:30:57 CET 2012


Author: romain
Date: 2012-12-03 15:30:56 +0100 (Mon, 03 Dec 2012)
New Revision: 4062

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/sugar/sets.h
Log:
support hash<String>

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-12-03 13:56:01 UTC (rev 4061)
+++ pkg/Rcpp/ChangeLog	2012-12-03 14:30:56 UTC (rev 4062)
@@ -16,6 +16,7 @@
         * include/Rcpp/traits/r_type_traits.h: support for String
         * unitTests/cpp/String.cpp : unit tests for String
         * unitTests/runit.String.R: unit test for String
+        * include/Rcpp/sugar/sets.h: support for String
 
 2012-12-01  Dirk Eddelbuettel  <edd at debian.org>
 

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/sets.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/sets.h	2012-12-03 13:56:01 UTC (rev 4061)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/sets.h	2012-12-03 14:30:56 UTC (rev 4062)
@@ -25,12 +25,37 @@
 #if __cplusplus >= 201103L
     #define RCPP_UNORDERED_SET std::unordered_set
     #define RCPP_UNORDERED_MAP std::unordered_map
+    
+    namespace std { 
+        template<>
+        struct hash<Rcpp::String> {
+            std::size_t operator()(const Rcpp::String& key) const {
+                return pointer_hasher( key.get_sexp() ) ;
+            }
+            hash<SEXP> pointer_hasher ;
+        };
+    }
+  
 #elif defined(HAS_TR1_UNORDERED_SET)
     #define RCPP_UNORDERED_SET std::tr1::unordered_set
     #define RCPP_UNORDERED_MAP std::tr1::unordered_map
+    
+    namespace std { 
+        namespace tr1 { 
+            template<>
+            struct hash<Rcpp::String> {
+                std::size_t operator()(const Rcpp::String& key) const {
+                    return pointer_hasher( key.get_sexp() ) ;
+                }
+                hash<SEXP> pointer_hasher ;
+            };
+        }
+    }
+  
+    
 #else
     #define RCPP_UNORDERED_SET std::set
-    #define RCPP_UNORDERED_MAP std::map
+    #define RCPP_UNORDERED_MAP std::map  
 #endif
 
 #endif



More information about the Rcpp-commits mailing list