From 7fe47a9d5b1727a61dc724523b530762f6d6ba19 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Thu, 30 Jun 2022 21:38:53 -0700 Subject: Restructure project --- app/source/Cplt/Utils/IO/TslRobinIntegration.hpp | 78 ++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 app/source/Cplt/Utils/IO/TslRobinIntegration.hpp (limited to 'app/source/Cplt/Utils/IO/TslRobinIntegration.hpp') diff --git a/app/source/Cplt/Utils/IO/TslRobinIntegration.hpp b/app/source/Cplt/Utils/IO/TslRobinIntegration.hpp new file mode 100644 index 0000000..bdea505 --- /dev/null +++ b/app/source/Cplt/Utils/IO/TslRobinIntegration.hpp @@ -0,0 +1,78 @@ +#pragma once + +#include +#include + +#include +#include +#include + +namespace DataStreamAdapters { +template +struct TslRobinMap +{ + template + static void ReadFromDataStream(InputDataStream& stream, tsl::robin_map& map) + { + static_assert(std::is_default_constructible_v); + static_assert(std::is_move_constructible_v); + + uint64_t size; + stream.Read(size); + map.reserve(size); + + for (uint64_t i = 0; i < size; ++i) { + TKey key; + ReadHelper(stream, key); + + TValue value; + ReadHelper(stream, value); + + map.insert(std::move(key), std::move(value)); + } + } + + template + static void WriteToDataStream(OutputDataStream& stream, const tsl::robin_map& map) + { + stream.Write((uint64_t)map.size()); + + for (auto it = map.begin(); it != map.end(); ++it) { + WriteHelper(stream, it.key()); + WriteHelper(stream, it.value()); + } + } +}; + +template +struct TslRobinSet +{ + template + static void ReadFromDataStream(InputDataStream& stream, tsl::robin_set& set) + { + static_assert(std::is_default_constructible_v); + static_assert(std::is_move_constructible_v); + + uint64_t size; + stream.Read(size); + set.reserve(size); + + for (uint64_t i = 0; i < size; ++i) { + TElement element; + ReadHelper(stream, element); + + set.insert(std::move(element)); + } + } + + template + static void WriteToDataStream(OutputDataStream& stream, const tsl::robin_set& set) + { + stream.Write((uint64_t)set.size()); + + for (auto& element : set) { + WriteHelper(stream, element); + } + } +}; +} // namespace DataStreamAdapters -- cgit v1.2.3-70-g09d2