diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-21 15:57:05 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-21 15:57:05 +1000 |
commit | 391527d81252e0fbb1095faf39305351980af816 (patch) | |
tree | 16b103a0a719f54d93b91d6675230777a6209e81 /source/core/StarXXHash.hpp | |
parent | acc8bc02800ce97dbc5424a3d83a1add1593349d (diff) |
Hashing improvements
Diffstat (limited to 'source/core/StarXXHash.hpp')
-rw-r--r-- | source/core/StarXXHash.hpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/source/core/StarXXHash.hpp b/source/core/StarXXHash.hpp index 28ef202..bce7566 100644 --- a/source/core/StarXXHash.hpp +++ b/source/core/StarXXHash.hpp @@ -5,7 +5,9 @@ #include "StarByteArray.hpp" #define XXH_STATIC_LINKING_ONLY +#define XXH_INLINE_ALL #include "xxhash.h" +#include "xxh3.h" namespace Star { @@ -31,6 +33,18 @@ private: XXH64_state_s state; }; +class XXHash3 { +public: + XXHash3(); + + void push(char const* data, size_t length); + uint64_t digest(); + +private: + XXH3_state_s state; +}; + + uint32_t xxHash32(char const* source, size_t length); uint32_t xxHash32(ByteArray const& in); uint32_t xxHash32(String const& in); @@ -39,6 +53,10 @@ uint64_t xxHash64(char const* source, size_t length); uint64_t xxHash64(ByteArray const& in); uint64_t xxHash64(String const& in); +uint64_t xxHash3(char const* source, size_t length); +uint64_t xxHash3(ByteArray const& in); +uint64_t xxHash3(String const& in); + #define XXHASH32_PRIMITIVE(TYPE, CAST_TYPE) \ inline void xxHash32Push(XXHash32& hash, TYPE const& v) { \ CAST_TYPE cv = v; \ @@ -53,6 +71,13 @@ uint64_t xxHash64(String const& in); hash.push((char const*)(&cv), sizeof(cv)); \ } +#define XXHASH3_PRIMITIVE(TYPE, CAST_TYPE) \ + inline void xxHash3Push(XXHash3& hash, TYPE const& v) { \ + CAST_TYPE cv = v; \ + cv = toLittleEndian(cv); \ + hash.push((char const*)(&cv), sizeof(cv)); \ + } + XXHASH32_PRIMITIVE(bool, bool); XXHASH32_PRIMITIVE(int, int32_t); XXHASH32_PRIMITIVE(long, int64_t); @@ -73,6 +98,16 @@ XXHASH64_PRIMITIVE(unsigned long long, uint64_t); XXHASH64_PRIMITIVE(float, float); XXHASH64_PRIMITIVE(double, double); +XXHASH3_PRIMITIVE(bool, bool); +XXHASH3_PRIMITIVE(int, int32_t); +XXHASH3_PRIMITIVE(long, int64_t); +XXHASH3_PRIMITIVE(long long, int64_t); +XXHASH3_PRIMITIVE(unsigned int, uint32_t); +XXHASH3_PRIMITIVE(unsigned long, uint64_t); +XXHASH3_PRIMITIVE(unsigned long long, uint64_t); +XXHASH3_PRIMITIVE(float, float); +XXHASH3_PRIMITIVE(double, double); + inline void xxHash32Push(XXHash32& hash, char const* str) { hash.push(str, strlen(str)); } @@ -89,6 +124,14 @@ inline void xxHash64Push(XXHash64& hash, String const& str) { hash.push(str.utf8Ptr(), str.size()); } +inline void xxHash3Push(XXHash3& hash, char const* str) { + hash.push(str, strlen(str)); +} + +inline void xxHash3Push(XXHash3& hash, String const& str) { + hash.push(str.utf8Ptr(), str.size()); +} + inline XXHash32::XXHash32(uint32_t seed) { XXH32_reset(&state, seed); } @@ -113,6 +156,18 @@ inline uint64_t XXHash64::digest() { return XXH64_digest(&state); } +inline XXHash3::XXHash3() { + XXH3_64bits_reset(&state); +} + +inline void XXHash3::push(char const* data, size_t length) { + XXH3_64bits_update(&state, data, length); +} + +inline uint64_t XXHash3::digest() { + return XXH3_64bits_digest(&state); +} + inline uint32_t xxHash32(char const* source, size_t length) { return XXH32(source, length, 0); } @@ -137,6 +192,17 @@ inline uint64_t xxHash64(String const& in) { return xxHash64(in.utf8Ptr(), in.utf8Size()); } +inline uint64_t xxHash3(char const* source, size_t length) { + return XXH3_64bits(source, length); +} + +inline uint64_t xxHash3(ByteArray const& in) { + return xxHash3(in.ptr(), in.size()); +} + +inline uint64_t xxHash3(String const& in) { + return xxHash3(in.utf8Ptr(), in.utf8Size()); +} } #endif |