aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/include
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2024-12-13 12:11:16 +0100
committerStefan Boberg <[email protected]>2024-12-13 12:11:16 +0100
commite4a7e9b30023c1c5195de9e78f02c075ff176460 (patch)
treeaaffd1e1954fba67f34969d2c2ead64d19d9d75f /src/zencore/include
parentadded ComputeOpKey so all instances of mapping key -> Oid is in a single place (diff)
downloadzen-e4a7e9b30023c1c5195de9e78f02c075ff176460.tar.xz
zen-e4a7e9b30023c1c5195de9e78f02c075ff176460.zip
fixed XXH3_128Stream so it initializes the state properly
the old version is still present for now, with a _deprecated suffix
Diffstat (limited to 'src/zencore/include')
-rw-r--r--src/zencore/include/zencore/xxhash.h31
1 files changed, 30 insertions, 1 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{};
};