From ab70e5461b98ddf2b56268c53c171cab89157027 Mon Sep 17 00:00:00 2001 From: Estevan Castilho Date: Thu, 2 Jul 2026 00:31:57 +0000 Subject: Nuke the old code --- src/TupleCodec.cpp | 67 ------------------------------------------------------ 1 file changed, 67 deletions(-) delete mode 100644 src/TupleCodec.cpp (limited to 'src/TupleCodec.cpp') diff --git a/src/TupleCodec.cpp b/src/TupleCodec.cpp deleted file mode 100644 index a78ed5b..0000000 --- a/src/TupleCodec.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "TupleCodec.h" - -#include - -#include -#include -#include -#include - -namespace nt::TupleCodec { - static std::vector Sorted(std::vector attrs) { - std::sort(attrs.begin(), attrs.end(), - [](const Attribute& a, const Attribute& b) { return a.name < b.name; }); - return attrs; - } - - std::string Hash(const std::vector& attrs) { - auto bytes = Serialize(attrs); - return picosha2::hash256_hex_string(bytes.begin(), bytes.end()); - } - - std::vector Serialize(const std::vector& attrs) { - // Format: [uint32_le name_len][name][uint32_le value_len][value] ... - // Attributes are stored in sorted name order for determinism. - std::vector out; - auto write_u32 = [&](uint32_t n) { - out.push_back(static_cast(n)); - out.push_back(static_cast(n >> 8)); - out.push_back(static_cast(n >> 16)); - out.push_back(static_cast(n >> 24)); - }; - - for (const auto& a : Sorted({attrs.begin(), attrs.end()})) { - write_u32(static_cast(a.name.size())); - out.insert(out.end(), a.name.begin(), a.name.end()); - write_u32(static_cast(a.value.size())); - out.insert(out.end(), a.value.begin(), a.value.end()); - } - return out; - } - - std::vector Deserialize(const std::vector& bytes) { - auto read_u32 = [&](size_t pos) -> uint32_t { - return static_cast(bytes[pos]) | - (static_cast(bytes[pos + 1]) << 8) | - (static_cast(bytes[pos + 2]) << 16) | - (static_cast(bytes[pos + 3]) << 24); - }; - - std::vector result; - size_t pos = 0; - while (pos + 8 <= bytes.size()) { - uint32_t name_len = read_u32(pos); - pos += 4; - std::string name(reinterpret_cast(bytes.data() + pos), name_len); - pos += name_len; - - uint32_t value_len = read_u32(pos); - pos += 4; - std::string value(reinterpret_cast(bytes.data() + pos), value_len); - pos += value_len; - - result.push_back({std::move(name), std::move(value)}); - } - return result; - } -} // namespace nt::TupleCodec -- cgit v1.2.3