Skip to content

Commit

Permalink
Print uint64_t using PRIx format macro
Browse files Browse the repository at this point in the history
  • Loading branch information
eddelbuettel committed Mar 10, 2024
1 parent 1fcf45c commit f215106
Showing 1 changed file with 7 additions and 34 deletions.
41 changes: 7 additions & 34 deletions src/digest.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,13 @@ SEXP digest(SEXP Txt, SEXP Algo, SEXP Length, SEXP Skip, SEXP Leave_raw, SEXP Se
break;
}
case 6: { /* xxhash32 case */
unsigned int val = XXH32(txt, nChar, seed);
XXH32_hash_t val = XXH32(txt, nChar, seed);
snprintf(output, 128, "%08x", val);
break;
}
case 7: { /* xxhash64 case */
unsigned long long val = XXH64(txt, nChar, seed);
#if defined(WIN32) && !defined(_UCRT)
XXH64_hash_t val = XXH64(txt, nChar, seed);
snprintf(output, 128, "%016" PRIx64, val);
#else
snprintf(output, 128, "%016llx", val);
#endif
break;
}
case 8: { /* MurmurHash3 32 */
Expand Down Expand Up @@ -241,20 +237,12 @@ SEXP digest(SEXP Txt, SEXP Algo, SEXP Length, SEXP Skip, SEXP Leave_raw, SEXP Se
}
case 12: { /* xxh3_64bits */
XXH64_hash_t val = XXH3_64bits_withSeed(txt, nChar, seed);
#if defined(WIN32) && !defined(_UCRT)
snprintf(output, 128, "%016" PRIx64, val);
#else
snprintf(output, 128, "%016lx", val);
#endif
break;
}
case 13: { /* xxh3_128bits */
XXH128_hash_t val = XXH3_128bits_withSeed(txt, nChar, seed);
#if defined(WIN32) && !defined(_UCRT)
snprintf(output, 128, "%016" PRIx64, val);
#else
snprintf(output, 128, "%016lx%016lx", val.high64, val.low64);
#endif
snprintf(output, 128, "%016" PRIx64 "%016" PRIx64, val.high64, val.low64);
break;
}
case 101: { /* md5 file case */
Expand Down Expand Up @@ -419,7 +407,7 @@ SEXP digest(SEXP Txt, SEXP Algo, SEXP Length, SEXP Skip, SEXP Leave_raw, SEXP Se
}
}
}
unsigned int val = XXH32_digest(state);
XXH32_hash_t val = XXH32_digest(state);
XXH32_freeState(state);

snprintf(output, 128, "%08x", val);
Expand All @@ -445,20 +433,15 @@ SEXP digest(SEXP Txt, SEXP Algo, SEXP Length, SEXP Skip, SEXP Leave_raw, SEXP Se
}
} else {
while ( ( nChar = fread( buf, 1, sizeof( buf ), fp ) ) > 0) {
XXH_errorcode const updateResult = XXH64_update(state, buf, nChar);
XXH_errorcode const updateResult = XXH64_update(state, buf, nChar);
if (updateResult == XXH_ERROR) {
error("Error in `XXH64_update()`"); /* #nocov */
}
}
}
unsigned long long val = XXH64_digest(state);
XXH64_hash_t val = XXH64_digest(state);
XXH64_freeState(state);

#ifdef WIN32
snprintf(output, 128, "%016" PRIx64, val);
#else
snprintf(output, 128, "%016llx", val);
#endif
break;
}
case 108: { /* murmur32 */
Expand Down Expand Up @@ -560,12 +543,7 @@ SEXP digest(SEXP Txt, SEXP Algo, SEXP Length, SEXP Skip, SEXP Leave_raw, SEXP Se
}
XXH64_hash_t val = XXH3_64bits_digest(state);
XXH3_freeState(state);

#ifdef WIN32
snprintf(output, 128, "%016" PRIx64, val);
#else
snprintf(output, 128, "%016lx", val);
#endif
break;
}
case 113: { /* xxh3_128 */
Expand Down Expand Up @@ -596,12 +574,7 @@ SEXP digest(SEXP Txt, SEXP Algo, SEXP Length, SEXP Skip, SEXP Leave_raw, SEXP Se
}
XXH128_hash_t val = XXH3_128bits_digest(state);
XXH3_freeState(state);

#if defined(WIN32) && !defined(_UCRT)
snprintf(output, 128, "%016" PRIx64, val);
#else
snprintf(output, 128, "%016lx%016lx", val.high64, val.low64);
#endif
snprintf(output, 128, "%016" PRIx64 "%016" PRIx64, val.high64, val.low64);
break;
}

Expand Down

0 comments on commit f215106

Please sign in to comment.