|
2 | 2 | #ifndef XXHASH_H |
3 | 3 | #define XXHASH_H |
4 | 4 | #include <jsi/jsi.h> |
5 | | -#include "xxhash.h" |
6 | 5 | #include <iomanip> |
7 | 6 | #include <sstream> |
| 7 | +#include "xxhash.h" |
8 | 8 |
|
9 | 9 | using namespace facebook; |
10 | 10 |
|
11 | 11 | namespace xxhash { |
12 | | - enum class HashSize { |
13 | | - BITS_64, |
14 | | - BITS_128, |
15 | | - }; |
16 | | - |
17 | | - template <HashSize T> |
18 | | - inline void make_hash(const std::string_view str, std::stringstream& ss) noexcept; |
19 | | - |
20 | | - template <> |
21 | | - inline void make_hash<HashSize::BITS_64>(const std::string_view str, |
22 | | - std::stringstream& ss) noexcept { |
23 | | - XXH64_hash_t hash = XXH3_64bits(str.data(), str.size()); |
24 | | - |
25 | | - ss << std::hex << std::setfill('0') << std::setw(16) << hash; |
26 | | - }; |
27 | | - |
28 | | - template <> |
29 | | - inline void make_hash<HashSize::BITS_128>(const std::string_view str, |
30 | | - std::stringstream& ss) noexcept { |
31 | | - XXH128_hash_t hash = XXH3_128bits(str.data(), str.size()); |
32 | | - |
33 | | - ss << std::hex << std::setfill('0') << std::setw(16) << hash.high64 |
34 | | - << std::setw(16) << hash.low64; |
35 | | - }; |
36 | | - |
37 | | - void install(jsi::Runtime* rt); |
38 | | -} |
39 | 12 |
|
| 13 | +inline void make_hash_64(const std::string_view str, char result[17]) noexcept { |
| 14 | + XXH64_hash_t hash = XXH3_64bits(str.data(), str.size()); |
| 15 | + std::snprintf(result, 17, "%016llx", hash); |
| 16 | +}; |
40 | 17 |
|
| 18 | +inline void make_hash_128(const std::string_view str, |
| 19 | + char result[33]) noexcept { |
| 20 | + XXH128_hash_t hash = XXH3_128bits(str.data(), str.size()); |
| 21 | + std::snprintf(result, 33, "%016llx%016llx", hash.high64, hash.low64); |
| 22 | +}; |
41 | 23 |
|
| 24 | +void install(jsi::Runtime* rt); |
| 25 | +} // namespace xxhash |
42 | 26 |
|
43 | 27 | #endif /* XXHASH_H */ |
0 commit comments