diff options
| author | Stefan Boberg <[email protected]> | 2025-03-11 21:24:02 +0100 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2025-03-11 21:24:02 +0100 |
| commit | 238778b4f0a5560ae07702aafea1a47b222e98e6 (patch) | |
| tree | 5ced4037d2f87c60fe9187f608953ecba7b066d0 /src/zenutil | |
| parent | eligeble -> eligible (diff) | |
| download | zen-238778b4f0a5560ae07702aafea1a47b222e98e6.tar.xz zen-238778b4f0a5560ae07702aafea1a47b222e98e6.zip | |
added support for delta-encoding of main manifest
reduces size of test data to less than half of the non-delta version
after compression the delta version is less than 20% of the original representation
Diffstat (limited to 'src/zenutil')
| -rw-r--r-- | src/zenutil/include/zenutil/chunkedcontent.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/zenutil/include/zenutil/chunkedcontent.h b/src/zenutil/include/zenutil/chunkedcontent.h index 309341550..533ec431f 100644 --- a/src/zenutil/include/zenutil/chunkedcontent.h +++ b/src/zenutil/include/zenutil/chunkedcontent.h @@ -195,6 +195,25 @@ namespace compactbinary_helpers { WriteArray(std::span<const Type>(Values), ArrayName, Output); } + inline void WriteDeltaArray(std::span<const uint32_t> Values, std::string_view ArrayName, CbWriter& Output) + { + Output.BeginArray(ArrayName); + uint32_t PreviousValue = 0; + for (const uint32_t Value : Values) + { + int64_t Delta = int64_t(Value) - PreviousValue; + uint64_t DeltaZigZag = (Delta >= 0) ? (Delta << 1) : (((-Delta - 1) << 1) | 1); + Output.AddInteger(DeltaZigZag); + PreviousValue = Value; + } + Output.EndArray(); + } + + inline void WriteDeltaArray(const std::vector<uint32_t>& Values, std::string_view ArrayName, CbWriter& Output) + { + WriteDeltaArray(std::span<const uint32_t>(Values), ArrayName, Output); + } + template<> inline void WriteArray(std::span<const std::filesystem::path> Values, std::string_view ArrayName, CbWriter& Output) { @@ -237,6 +256,20 @@ namespace compactbinary_helpers { } } + inline void ReadDeltaArray(std::string_view ArrayName, CbObjectView Input, std::vector<uint32_t>& Result) + { + CbArrayView Array = Input[ArrayName].AsArrayView(); + Result.reserve(Array.Num()); + uint32_t PreviousValue = 0; + for (CbFieldView ItemView : Array) + { + uint64_t DeltaZigZag = ItemView.AsUInt64(); + const int64_t Delta = (DeltaZigZag & 1) ? -int64_t((DeltaZigZag >> 1) + 1) : int64_t(DeltaZigZag >> 1); + PreviousValue = uint32_t(PreviousValue + Delta); + Result.push_back(PreviousValue); + } + } + inline void ReadArray(std::string_view ArrayName, CbObjectView Input, std::vector<uint64_t>& Result) { CbArrayView Array = Input[ArrayName].AsArrayView(); |