1
- // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
2
- //
1
+
3
2
// IndexHash.h: Rcpp R/C++ interface class library -- hashing utility, inspired
4
3
// from Simon's fastmatch package
5
4
//
@@ -43,7 +42,7 @@ namespace Rcpp{
43
42
namespace sugar {
44
43
45
44
#ifndef RCPP_HASH
46
- #define RCPP_HASH (X ) (3141592653U * ((unsigned int )(X)) >> (32 - k))
45
+ #define RCPP_HASH (X ) (3141592653U * ((uint32_t )(X)) >> (32 - k))
47
46
#endif
48
47
49
48
template <int RTYPE>
@@ -100,7 +99,7 @@ namespace Rcpp{
100
99
}
101
100
102
101
inline bool contains (STORAGE val) const {
103
- return get_index (val) != static_cast <unsigned int >(NA_INTEGER);
102
+ return get_index (val) != static_cast <uint32_t >(NA_INTEGER);
104
103
}
105
104
106
105
inline int size () const {
@@ -167,10 +166,10 @@ namespace Rcpp{
167
166
bool add_value (int i){
168
167
RCPP_DEBUG_2 ( " %s::add_value(%d)" , DEMANGLE (IndexHash), i )
169
168
STORAGE val = src[i++] ;
170
- unsigned int addr = get_addr (val) ;
169
+ uint32_t addr = get_addr (val) ;
171
170
while (data[addr] && not_equal ( src[data[addr] - 1 ], val)) {
172
171
addr++;
173
- if (addr == static_cast <unsigned int >(m)) {
172
+ if (addr == static_cast <uint32_t >(m)) {
174
173
addr = 0 ;
175
174
}
176
175
}
@@ -185,31 +184,31 @@ namespace Rcpp{
185
184
}
186
185
187
186
/* NOTE: we are returning a 1-based index ! */
188
- inline unsigned int get_index (STORAGE value) const {
189
- unsigned int addr = get_addr (value) ;
187
+ inline uint32_t get_index (STORAGE value) const {
188
+ uint32_t addr = get_addr (value) ;
190
189
while (data[addr]) {
191
190
if (src[data[addr] - 1 ] == value)
192
191
return data[addr];
193
192
addr++;
194
- if (addr == static_cast <unsigned int >(m)) addr = 0 ;
193
+ if (addr == static_cast <uint32_t >(m)) addr = 0 ;
195
194
}
196
195
return NA_INTEGER;
197
196
}
198
197
199
198
// defined below
200
- unsigned int get_addr (STORAGE value) const ;
199
+ uint32_t get_addr (STORAGE value) const ;
201
200
} ;
202
201
203
202
template <>
204
- inline unsigned int IndexHash<INTSXP>::get_addr(int value) const {
203
+ inline uint32_t IndexHash<INTSXP>::get_addr(int value) const {
205
204
return RCPP_HASH (value) ;
206
205
}
207
206
template <>
208
- inline unsigned int IndexHash<REALSXP>::get_addr(double val) const {
209
- unsigned int addr;
207
+ inline uint32_t IndexHash<REALSXP>::get_addr(double val) const {
208
+ uint32_t addr;
210
209
union dint_u {
211
210
double d;
212
- unsigned int u[2 ];
211
+ uint32_t u[2 ];
213
212
};
214
213
union dint_u val_u;
215
214
/* double is a bit tricky - we nave to normalize 0.0, NA and NaN */
@@ -222,9 +221,9 @@ namespace Rcpp{
222
221
}
223
222
224
223
template <>
225
- inline unsigned int IndexHash<STRSXP>::get_addr(SEXP value) const {
224
+ inline uint32_t IndexHash<STRSXP>::get_addr(SEXP value) const {
226
225
intptr_t val = (intptr_t ) value;
227
- unsigned int addr;
226
+ uint32_t addr;
228
227
#if (defined _LP64) || (defined __LP64__) || (defined WIN64)
229
228
addr = RCPP_HASH ((val & 0xffffffff ) ^ (val >> 32 ));
230
229
#else
0 commit comments