aboutsummaryrefslogtreecommitdiff
path: root/src/zencore
diff options
context:
space:
mode:
Diffstat (limited to 'src/zencore')
-rw-r--r--src/zencore/include/zencore/xxhash.h31
-rw-r--r--src/zencore/xxhash.cpp12
2 files changed, 40 insertions, 3 deletions
diff --git a/src/zencore/include/zencore/xxhash.h b/src/zencore/include/zencore/xxhash.h
index 94d98be98..1616e5f93 100644
--- a/src/zencore/include/zencore/xxhash.h
+++ b/src/zencore/include/zencore/xxhash.h
@@ -61,8 +61,10 @@ struct XXH3_128
struct XXH3_128Stream
{
+ XXH3_128Stream() { Reset(); }
+
/// Begin streaming hash compute (not needed on freshly constructed instance)
- void Reset() { memset(&m_State, 0, sizeof m_State); }
+ void Reset() { XXH3_128bits_reset(&m_State); }
/// Append another chunk
XXH3_128Stream& Append(const void* Data, size_t ByteCount)
@@ -83,6 +85,33 @@ struct XXH3_128Stream
}
private:
+ XXH3_state_s m_State;
+};
+
+struct XXH3_128Stream_deprecated
+{
+ /// Begin streaming hash compute (not needed on freshly constructed instance)
+ void Reset() { memset(&m_State, 0, sizeof m_State); }
+
+ /// Append another chunk
+ XXH3_128Stream_deprecated& Append(const void* Data, size_t ByteCount)
+ {
+ XXH3_128bits_update(&m_State, Data, ByteCount);
+ return *this;
+ }
+
+ /// Append another chunk
+ XXH3_128Stream_deprecated& Append(MemoryView Data) { return Append(Data.GetData(), Data.GetSize()); }
+
+ /// Obtain final hash. If you wish to reuse the instance call reset()
+ XXH3_128 GetHash()
+ {
+ XXH3_128 Hash;
+ XXH128_canonicalFromHash((XXH128_canonical_t*)Hash.Hash, XXH3_128bits_digest(&m_State));
+ return Hash;
+ }
+
+private:
XXH3_state_s m_State{};
};
diff --git a/src/zencore/xxhash.cpp b/src/zencore/xxhash.cpp
index ff88a4372..80d7bc8fd 100644
--- a/src/zencore/xxhash.cpp
+++ b/src/zencore/xxhash.cpp
@@ -69,12 +69,20 @@ TEST_CASE("XXH3_128")
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"};
+ SUBCASE("short_deprecated")
+ {
+ XXH3_128Stream_deprecated x;
+ x.Append(ShortString.data(), ShortString.size());
+ const XXH3_128 Hash = x.GetHash();
+ CHECK(Hash == XXH3_128::FromHexString("0d44dd7fde8ea2b4ba961e1a26f71f21"sv));
+ }
+
SUBCASE("short")
{
XXH3_128Stream x;
x.Append(ShortString.data(), ShortString.size());
const XXH3_128 Hash = x.GetHash();
- CHECK(Hash == XXH3_128::FromHexString("0d44dd7fde8ea2b4ba961e1a26f71f21"sv));
+ CHECK(Hash == XXH3_128::FromHexString("9a4dea864648af82823c8c03e6dd2202"sv));
}
SUBCASE("long")
@@ -82,7 +90,7 @@ TEST_CASE("XXH3_128")
XXH3_128Stream x;
x.Append(LongString.data(), LongString.size());
const XXH3_128 Hash = x.GetHash();
- CHECK(Hash == XXH3_128::FromHexString("bc408748826fb22da051517c97c9d181"sv));
+ CHECK(Hash == XXH3_128::FromHexString("fbd5e72f7a5894590d1ef49dfcc58b7d"sv));
}
}