Skip to content

Commit adae3fe

Browse files
authored
Merge pull request #561 from thirdwing/iss391_patch2
change hashing function to return unsigned int
2 parents 4e14955 + 4f53bc2 commit adae3fe

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
* inst/unitTests/runit.sugar.R: Idem
88
* inst/unitTests/runit.dispatch.R (test.ExpressionVector): Use
99
expression rather than parse, correct typo
10+
2016-10-22 Qiang Kou <[email protected]>
11+
12+
* inst/include/Rcpp/hash/IndexHash.h: change hashing function to return unsigned int
13+
* inst/include/Rcpp/hash/SelfHash.h: Ditto
14+
1015

1116
2016-10-21 Qiang Kou <[email protected]>
1217

inst/NEWS.Rd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
\itemize{
1010
\item String and vector elements now use extended \code{R_xlen_t} indices
1111
(Qiang in PR \ghpr{560})
12+
\item Hashing functions now return unsigned int (Qiang in PR \ghpr{561})
1213
}
1314
\item Changes in Rcpp Sugar:
1415
\itemize{

inst/include/Rcpp/hash/IndexHash.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ namespace Rcpp{
167167
bool add_value(int i){
168168
RCPP_DEBUG_2( "%s::add_value(%d)", DEMANGLE(IndexHash), i )
169169
STORAGE val = src[i++] ;
170-
int addr = get_addr(val) ;
170+
unsigned int addr = get_addr(val) ;
171171
while (data[addr] && not_equal( src[data[addr] - 1], val)) {
172172
addr++;
173173
if (addr == m) {
@@ -185,8 +185,8 @@ namespace Rcpp{
185185
}
186186

187187
/* NOTE: we are returning a 1-based index ! */
188-
inline int get_index(STORAGE value) const {
189-
int addr = get_addr(value) ;
188+
inline unsigned int get_index(STORAGE value) const {
189+
unsigned int addr = get_addr(value) ;
190190
while (data[addr]) {
191191
if (src[data[addr] - 1] == value)
192192
return data[addr];
@@ -197,16 +197,16 @@ namespace Rcpp{
197197
}
198198

199199
// defined below
200-
int get_addr(STORAGE value) const ;
200+
unsigned int get_addr(STORAGE value) const ;
201201
} ;
202202

203203
template <>
204-
inline int IndexHash<INTSXP>::get_addr(int value) const {
204+
inline unsigned int IndexHash<INTSXP>::get_addr(int value) const {
205205
return RCPP_HASH(value) ;
206206
}
207207
template <>
208-
inline int IndexHash<REALSXP>::get_addr(double val) const {
209-
int addr;
208+
inline unsigned int IndexHash<REALSXP>::get_addr(double val) const {
209+
unsigned int addr;
210210
union dint_u {
211211
double d;
212212
unsigned int u[2];
@@ -222,9 +222,9 @@ namespace Rcpp{
222222
}
223223

224224
template <>
225-
inline int IndexHash<STRSXP>::get_addr(SEXP value) const {
225+
inline unsigned int IndexHash<STRSXP>::get_addr(SEXP value) const {
226226
intptr_t val = (intptr_t) value;
227-
int addr;
227+
unsigned int addr;
228228
#if (defined _LP64) || (defined __LP64__) || (defined WIN64)
229229
addr = RCPP_HASH((val & 0xffffffff) ^ (val >> 32));
230230
#else

inst/include/Rcpp/hash/SelfHash.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace sugar{
6262

6363
int add_value_get_index(int i){
6464
STORAGE val = src[i++] ;
65-
int addr = get_addr(val) ;
65+
unsigned int addr = get_addr(val) ;
6666
while (data[addr] && src[data[addr] - 1] != val) {
6767
addr++;
6868
if (addr == m) addr = 0;
@@ -75,8 +75,8 @@ namespace sugar{
7575
}
7676

7777
/* NOTE: we are returning a 1-based index ! */
78-
int get_index(STORAGE value) const {
79-
int addr = get_addr(value) ;
78+
unsigned int get_index(STORAGE value) const {
79+
unsigned int addr = get_addr(value) ;
8080
while (data[addr]) {
8181
if (src[data[addr] - 1] == value)
8282
return data[addr];
@@ -87,16 +87,16 @@ namespace sugar{
8787
}
8888

8989
// defined below
90-
int get_addr(STORAGE value) const ;
90+
unsigned int get_addr(STORAGE value) const ;
9191
} ;
9292

9393
template <>
94-
inline int SelfHash<INTSXP>::get_addr(int value) const {
94+
inline unsigned int SelfHash<INTSXP>::get_addr(int value) const {
9595
return RCPP_HASH(value) ;
9696
}
9797
template <>
98-
inline int SelfHash<REALSXP>::get_addr(double val) const {
99-
int addr;
98+
inline unsigned int SelfHash<REALSXP>::get_addr(double val) const {
99+
unsigned int addr;
100100
union dint_u {
101101
double d;
102102
unsigned int u[2];
@@ -112,9 +112,9 @@ namespace sugar{
112112
}
113113

114114
template <>
115-
inline int SelfHash<STRSXP>::get_addr(SEXP value) const {
115+
inline unsigned int SelfHash<STRSXP>::get_addr(SEXP value) const {
116116
intptr_t val = (intptr_t) value;
117-
int addr;
117+
unsigned int addr;
118118
#if (defined _LP64) || (defined __LP64__) || (defined WIN64)
119119
addr = RCPP_HASH((val & 0xffffffff) ^ (val >> 32));
120120
#else

0 commit comments

Comments
 (0)