diff --git a/uppsrc/Core/Hash.h b/uppsrc/Core/Hash.h index cf136e495..981be4fc1 100644 --- a/uppsrc/Core/Hash.h +++ b/uppsrc/Core/Hash.h @@ -75,4 +75,20 @@ public: int xxHash(const void *data, size_t len); int xxHash(const String& s); +class xxHash64Stream : public OutStream { + byte context[12 * 8]; + + virtual void Out(const void *data, dword size); + +public: + int64 Finish(); + + void Reset(dword seed = 0); + + xxHash64Stream(dword seed = 0); +}; + +int64 xxHash64(const void *data, size_t len); +int64 xxHash64(const String& s); + #endif diff --git a/uppsrc/Core/xxHsh.cpp b/uppsrc/Core/xxHsh.cpp index efadbba47..dfd98cf4c 100644 --- a/uppsrc/Core/xxHsh.cpp +++ b/uppsrc/Core/xxHsh.cpp @@ -38,4 +38,38 @@ int xxHash(const String& s) return xxHash(~s, s.GetCount()); } +xxHash64Stream::xxHash64Stream(dword seed) +{ + STATIC_ASSERT(sizeof(context) >= sizeof(XXH64_state_t)); + Reset(seed); +} + +void xxHash64Stream::Reset(dword seed) +{ + XXH64_reset((XXH64_state_t *)context, seed); +} + +void xxHash64Stream::Out(const void *data, dword size) +{ + XXH64_update((XXH64_state_t *)context, data, size); +} + +int64 xxHash64Stream::Finish() +{ + Flush(); + return XXH64_digest((XXH64_state_t *)context); +} + +int64 xxHash64(const void *data, size_t len) +{ + xxHash64Stream h; + h.Put64(data, len); + return h.Finish(); +} + +int64 xxHash64(const String& s) +{ + return xxHash64(~s, s.GetCount()); +} + }; \ No newline at end of file