/usr/lib/R/site-library/dplyr/include/dplyr/VectorVisitorImpl.h is in r-cran-dplyr 0.7.4-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | #ifndef dplyr_VectorVisitor_Impl_H
#define dplyr_VectorVisitor_Impl_H
#include <tools/collapse.h>
#include <tools/utils.h>
#include <dplyr/CharacterVectorOrderer.h>
#include <dplyr/comparisons.h>
#include <dplyr/VectorVisitor.h>
#include <tools/encoding.h>
namespace dplyr {
template <int RTYPE> std::string VectorVisitorType();
template <> inline std::string VectorVisitorType<INTSXP>() {
return "integer";
}
template <> inline std::string VectorVisitorType<REALSXP>() {
return "numeric";
}
template <> inline std::string VectorVisitorType<LGLSXP>() {
return "logical";
}
template <> inline std::string VectorVisitorType<STRSXP>() {
return "character";
}
template <> inline std::string VectorVisitorType<CPLXSXP>() {
return "complex";
}
template <> inline std::string VectorVisitorType<VECSXP>() {
return "list";
}
/**
* Implementations
*/
template <int RTYPE>
class VectorVisitorImpl : public VectorVisitor {
typedef comparisons<RTYPE> compare;
public:
typedef Rcpp::Vector<RTYPE> VECTOR;
/**
* The type of data : int, double, SEXP, Rcomplex
*/
typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE;
/**
* Hasher for that type of data
*/
typedef boost::hash<STORAGE> hasher;
VectorVisitorImpl(const VECTOR& vec_) : vec(vec_) {}
/**
* implementations
*/
size_t hash(int i) const {
return hash_fun(vec[i]);
}
inline bool equal(int i, int j) const {
return compare::equal_or_both_na(vec[i], vec[j]);
}
inline bool less(int i, int j) const {
return compare::is_less(vec[i], vec[j]);
}
inline bool equal_or_both_na(int i, int j) const {
return compare::equal_or_both_na(vec[i], vec[j]);
}
inline bool greater(int i, int j) const {
return compare::is_greater(vec[i], vec[j]);
}
inline std::string get_r_type() const {
return VectorVisitorType<RTYPE>();
}
int size() const {
return vec.size();
}
bool is_na(int i) const {
return VECTOR::is_na(vec[i]);
}
protected:
VECTOR vec;
hasher hash_fun;
};
class FactorVisitor : public VectorVisitorImpl<INTSXP> {
typedef comparisons<STRSXP> string_compare;
public:
typedef VectorVisitorImpl<INTSXP> Parent;
FactorVisitor(const IntegerVector& vec_) : Parent(vec_) {
levels = get_levels(vec);
levels_ptr = Rcpp::internal::r_vector_start<STRSXP>(levels);
}
inline bool equal(int i, int j) const {
return vec[i] == vec[j];
}
inline bool less(int i, int j) const {
return
string_compare::is_less(
vec[i] < 0 ? NA_STRING : levels_ptr[vec[i]],
vec[j] < 0 ? NA_STRING : levels_ptr[vec[j]]
);
}
inline bool greater(int i, int j) const {
return
string_compare::is_greater(
vec[i] < 0 ? NA_STRING : levels_ptr[vec[i]],
vec[j] < 0 ? NA_STRING : levels_ptr[vec[j]]
);
}
inline std::string get_r_type() const {
return get_single_class(Parent::vec);
}
private:
CharacterVector levels;
SEXP* levels_ptr;
};
template <>
class VectorVisitorImpl<STRSXP> : public VectorVisitor {
public:
VectorVisitorImpl(const CharacterVector& vec_) :
vec(reencode_char(vec_)), has_orders(false)
{}
size_t hash(int i) const {
return reinterpret_cast<size_t>(get_item(i));
}
inline bool equal(int i, int j) const {
return equal_or_both_na(i, j);
}
inline bool less(int i, int j) const {
provide_orders();
return orders[i] < orders[j];
}
inline bool equal_or_both_na(int i, int j) const {
return get_item(i) == get_item(j);
}
inline bool greater(int i, int j) const {
provide_orders();
return orders[i] > orders[j];
}
inline std::string get_r_type() const {
return VectorVisitorType<STRSXP>();
}
int size() const {
return vec.size();
}
bool is_na(int i) const {
return CharacterVector::is_na(vec[i]);
}
private:
SEXP get_item(const int i) const {
return static_cast<SEXP>(vec[i]);
}
void provide_orders() const {
if (has_orders)
return;
orders = CharacterVectorOrderer(vec).get();
has_orders = true;
}
private:
CharacterVector vec;
mutable IntegerVector orders;
mutable bool has_orders;
};
}
#endif
|