MCPcopy Create free account
hub / github.com/RcppCore/Rcpp / Table

Class Table

inst/include/Rcpp/sugar/functions/table.h:58–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56
57template <int RTYPE, typename TABLE_T>
58class Table {
59public:
60 typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
61
62 Table( const TABLE_T& table ): hash(), map() {
63 // populate the initial hash
64 std::for_each( table.begin(), table.end(), Inserter(hash) ) ;
65
66 // populate the map, sorted by keys
67 map.insert( hash.begin(), hash.end() ) ;
68 }
69
70 inline operator IntegerVector() const {
71 // fill the result
72 R_xlen_t n = map.size() ;
73 IntegerVector result = no_init(n) ;
74 CharacterVector names = no_init(n) ;
75 std::for_each( map.begin(), map.end(), Grabber<SORTED_MAP,RTYPE>(result, names) ) ;
76 result.names() = names ;
77 return result ;
78 }
79
80private:
81 typedef std::unordered_map<STORAGE, int> HASH ;
82 typedef CountInserter<HASH,STORAGE> Inserter ;
83 HASH hash ;
84
85 typedef std::map<STORAGE, int, internal::NAComparator<STORAGE> > SORTED_MAP ;
86 SORTED_MAP map ;
87
88};
89
90} // sugar
91

Callers

nothing calls this directly

Calls 5

no_initFunction · 0.85
namesMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected