-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
Hello, I wanted to store xxhash64 strings as integer64 and was surprised that there is no function that can convert hex strings directly to integer64.
As a workaround, I wrote a Rcpp function:
cppFunction('
NumericVector hex_to_int64_cpp(CharacterVector hex_strings) {
int n = hex_strings.size();
NumericVector out(n);
for(int i = 0; i < n; ++i) {
if (CharacterVector::is_na(hex_strings[i])) {
out[i] = NA_REAL;
} else {
const char* s = hex_strings[i];
char* endptr;
unsigned long long val = std::strtoull(s, &endptr, 16);
((unsigned long long*)out.begin())[i] = val;
}
}
out.attr("class") = "integer64";
return out;
}
')In my opinion, such a function would be quite practical for efficiently storing 64-bit hashes created with digest. Perhaps this could be an idea for a new feature. Thanks!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels