Skip to content

Commit

Permalink
Merge pull request #561 from thirdwing/iss391_patch2
Browse files Browse the repository at this point in the history
change hashing function to return unsigned int
  • Loading branch information
eddelbuettel committed Oct 24, 2016
2 parents 4e14955 + 4f53bc2 commit adae3fe
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
* inst/unitTests/runit.sugar.R: Idem
* inst/unitTests/runit.dispatch.R (test.ExpressionVector): Use
expression rather than parse, correct typo
2016-10-22 Qiang Kou <qkou@umail.iu.edu>

* inst/include/Rcpp/hash/IndexHash.h: change hashing function to return unsigned int
* inst/include/Rcpp/hash/SelfHash.h: Ditto


2016-10-21 Qiang Kou <qkou@umail.iu.edu>

Expand Down
1 change: 1 addition & 0 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
\itemize{
\item String and vector elements now use extended \code{R_xlen_t} indices
(Qiang in PR \ghpr{560})
\item Hashing functions now return unsigned int (Qiang in PR \ghpr{561})
}
\item Changes in Rcpp Sugar:
\itemize{
Expand Down
18 changes: 9 additions & 9 deletions inst/include/Rcpp/hash/IndexHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ namespace Rcpp{
bool add_value(int i){
RCPP_DEBUG_2( "%s::add_value(%d)", DEMANGLE(IndexHash), i )
STORAGE val = src[i++] ;
int addr = get_addr(val) ;
unsigned int addr = get_addr(val) ;
while (data[addr] && not_equal( src[data[addr] - 1], val)) {
addr++;
if (addr == m) {
Expand All @@ -185,8 +185,8 @@ namespace Rcpp{
}

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

// defined below
int get_addr(STORAGE value) const ;
unsigned int get_addr(STORAGE value) const ;
} ;

template <>
inline int IndexHash<INTSXP>::get_addr(int value) const {
inline unsigned int IndexHash<INTSXP>::get_addr(int value) const {
return RCPP_HASH(value) ;
}
template <>
inline int IndexHash<REALSXP>::get_addr(double val) const {
int addr;
inline unsigned int IndexHash<REALSXP>::get_addr(double val) const {
unsigned int addr;
union dint_u {
double d;
unsigned int u[2];
Expand All @@ -222,9 +222,9 @@ namespace Rcpp{
}

template <>
inline int IndexHash<STRSXP>::get_addr(SEXP value) const {
inline unsigned int IndexHash<STRSXP>::get_addr(SEXP value) const {
intptr_t val = (intptr_t) value;
int addr;
unsigned int addr;
#if (defined _LP64) || (defined __LP64__) || (defined WIN64)
addr = RCPP_HASH((val & 0xffffffff) ^ (val >> 32));
#else
Expand Down
18 changes: 9 additions & 9 deletions inst/include/Rcpp/hash/SelfHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace sugar{

int add_value_get_index(int i){
STORAGE val = src[i++] ;
int addr = get_addr(val) ;
unsigned int addr = get_addr(val) ;
while (data[addr] && src[data[addr] - 1] != val) {
addr++;
if (addr == m) addr = 0;
Expand All @@ -75,8 +75,8 @@ namespace sugar{
}

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

// defined below
int get_addr(STORAGE value) const ;
unsigned int get_addr(STORAGE value) const ;
} ;

template <>
inline int SelfHash<INTSXP>::get_addr(int value) const {
inline unsigned int SelfHash<INTSXP>::get_addr(int value) const {
return RCPP_HASH(value) ;
}
template <>
inline int SelfHash<REALSXP>::get_addr(double val) const {
int addr;
inline unsigned int SelfHash<REALSXP>::get_addr(double val) const {
unsigned int addr;
union dint_u {
double d;
unsigned int u[2];
Expand All @@ -112,9 +112,9 @@ namespace sugar{
}

template <>
inline int SelfHash<STRSXP>::get_addr(SEXP value) const {
inline unsigned int SelfHash<STRSXP>::get_addr(SEXP value) const {
intptr_t val = (intptr_t) value;
int addr;
unsigned int addr;
#if (defined _LP64) || (defined __LP64__) || (defined WIN64)
addr = RCPP_HASH((val & 0xffffffff) ^ (val >> 32));
#else
Expand Down

0 comments on commit adae3fe

Please sign in to comment.