aboutsummaryrefslogtreecommitdiff
path: root/src/zenstore/chunking.h
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-10-23 15:24:20 +0200
committerGitHub <[email protected]>2023-10-23 15:24:20 +0200
commitfb413405e43d3a717b642360d73cfc61258e63b3 (patch)
tree5106b0482253219e02fa25c87a1ac0208d9d8600 /src/zenstore/chunking.h
parentfix m_LastFullGcDuration, m_LastFullGCDiff, m_LastFullGcDuration and m_LastLi... (diff)
downloadzen-fb413405e43d3a717b642360d73cfc61258e63b3.tar.xz
zen-fb413405e43d3a717b642360d73cfc61258e63b3.zip
chunking moved to zenstore (#490)
* moved chunking into zenstore * removed vestiges of experimental chunking command
Diffstat (limited to 'src/zenstore/chunking.h')
-rw-r--r--src/zenstore/chunking.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/zenstore/chunking.h b/src/zenstore/chunking.h
new file mode 100644
index 000000000..09c56454f
--- /dev/null
+++ b/src/zenstore/chunking.h
@@ -0,0 +1,56 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#pragma once
+#include <zencore/zencore.h>
+
+namespace zen {
+
+/** Content-defined chunking helper
+ */
+class ZenChunkHelper
+{
+public:
+ void SetChunkSize(size_t MinSize, size_t MaxSize, size_t AvgSize);
+ size_t ScanChunk(const void* DataBytes, size_t ByteCount);
+ void Reset();
+
+ // This controls which chunking approach is used - threshold or
+ // modulo based. Threshold is faster and generates similarly sized
+ // chunks
+ void SetUseThreshold(bool NewState) { m_UseThreshold = NewState; }
+
+ inline size_t ChunkSizeMin() const { return m_ChunkSizeMin; }
+ inline size_t ChunkSizeMax() const { return m_ChunkSizeMax; }
+ inline size_t ChunkSizeAvg() const { return m_ChunkSizeAvg; }
+ inline uint64_t BytesScanned() const { return m_BytesScanned; }
+
+ static constexpr size_t kNoBoundaryFound = size_t(~0ull);
+
+private:
+ size_t m_ChunkSizeMin = 0;
+ size_t m_ChunkSizeMax = 0;
+ size_t m_ChunkSizeAvg = 0;
+
+ uint32_t m_Discriminator = 0; // Computed in SetChunkSize()
+ uint32_t m_Threshold = 0; // Computed in SetChunkSize()
+
+ bool m_UseThreshold = true;
+
+ static constexpr size_t kChunkSizeLimitMax = 64 * 1024 * 1024;
+ static constexpr size_t kChunkSizeLimitMin = 1024;
+ static constexpr size_t kDefaultAverageChunkSize = 64 * 1024;
+
+ static constexpr int kWindowSize = 48;
+ uint8_t m_Window[kWindowSize];
+ uint32_t m_WindowSize = 0;
+
+ uint32_t m_CurrentHash = 0;
+ uint32_t m_CurrentChunkSize = 0;
+
+ uint64_t m_BytesScanned = 0;
+
+ size_t InternalScanChunk(const void* DataBytes, size_t ByteCount);
+ void InternalReset();
+};
+
+} // namespace zen