Skip to content

Commit 27f24f0

Browse files
authored
Merge pull request #1153 from RcppCore/issue1152
Suppress one 'int / unsigned int comparisom' warning
2 parents f326eba + b02a0f9 commit 27f24f0

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2021-04-09 Dirk Eddelbuettel <[email protected]>
2+
3+
* inst/include/Rcpp/hash/IndexHash.h: Silence one comparison, update
4+
use of unsigned it to uint32_t throughout
5+
16
2021-03-22 Dirk Eddelbuettel <[email protected]>
27

38
* DESCRIPTION (Version, Date): Roll minor version

inst/include/Rcpp/hash/IndexHash.h

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
2-
//
1+
32
// IndexHash.h: Rcpp R/C++ interface class library -- hashing utility, inspired
43
// from Simon's fastmatch package
54
//
6-
// Copyright (C) 2010, 2011 Simon Urbanek
7-
// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
8-
// Copyright (C) 2014 Dirk Eddelbuettel, Romain Francois and Kevin Ushey
5+
// Copyright (C) 2010, 2011 Simon Urbanek
6+
// Copyright (C) 2012 - 2013 Dirk Eddelbuettel and Romain Francois
7+
// Copyright (C) 2014 - 2021 Dirk Eddelbuettel, Romain Francois and Kevin Ushey
98
//
109
// This file is part of Rcpp.
1110
//
@@ -43,7 +42,7 @@ namespace Rcpp{
4342
namespace sugar{
4443

4544
#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))
4746
#endif
4847

4948
template <int RTYPE>
@@ -100,7 +99,7 @@ namespace Rcpp{
10099
}
101100

102101
inline bool contains(STORAGE val) const {
103-
return get_index(val) != NA_INTEGER ;
102+
return get_index(val) != static_cast<uint32_t>(NA_INTEGER);
104103
}
105104

106105
inline int size() const {
@@ -167,10 +166,10 @@ namespace Rcpp{
167166
bool add_value(int i){
168167
RCPP_DEBUG_2( "%s::add_value(%d)", DEMANGLE(IndexHash), i )
169168
STORAGE val = src[i++] ;
170-
unsigned int addr = get_addr(val) ;
169+
uint32_t addr = get_addr(val) ;
171170
while (data[addr] && not_equal( src[data[addr] - 1], val)) {
172171
addr++;
173-
if (addr == static_cast<unsigned int>(m)) {
172+
if (addr == static_cast<uint32_t>(m)) {
174173
addr = 0;
175174
}
176175
}
@@ -185,31 +184,31 @@ namespace Rcpp{
185184
}
186185

187186
/* 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) ;
190189
while (data[addr]) {
191190
if (src[data[addr] - 1] == value)
192191
return data[addr];
193192
addr++;
194-
if (addr == static_cast<unsigned int>(m)) addr = 0;
193+
if (addr == static_cast<uint32_t>(m)) addr = 0;
195194
}
196195
return NA_INTEGER;
197196
}
198197

199198
// defined below
200-
unsigned int get_addr(STORAGE value) const ;
199+
uint32_t get_addr(STORAGE value) const ;
201200
} ;
202201

203202
template <>
204-
inline unsigned int IndexHash<INTSXP>::get_addr(int value) const {
203+
inline uint32_t IndexHash<INTSXP>::get_addr(int value) const {
205204
return RCPP_HASH(value) ;
206205
}
207206
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;
210209
union dint_u {
211210
double d;
212-
unsigned int u[2];
211+
uint32_t u[2];
213212
};
214213
union dint_u val_u;
215214
/* double is a bit tricky - we nave to normalize 0.0, NA and NaN */
@@ -222,9 +221,9 @@ namespace Rcpp{
222221
}
223222

224223
template <>
225-
inline unsigned int IndexHash<STRSXP>::get_addr(SEXP value) const {
224+
inline uint32_t IndexHash<STRSXP>::get_addr(SEXP value) const {
226225
intptr_t val = (intptr_t) value;
227-
unsigned int addr;
226+
uint32_t addr;
228227
#if (defined _LP64) || (defined __LP64__) || (defined WIN64)
229228
addr = RCPP_HASH((val & 0xffffffff) ^ (val >> 32));
230229
#else
@@ -238,4 +237,3 @@ namespace Rcpp{
238237
} // Rcpp
239238

240239
#endif
241-

0 commit comments

Comments
 (0)