aboutsummaryrefslogtreecommitdiff
path: root/app/source/Cplt/Utils/IO/TslRobinIntegration.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-06-30 21:38:53 -0700
committerrtk0c <[email protected]>2022-06-30 21:38:53 -0700
commit7fe47a9d5b1727a61dc724523b530762f6d6ba19 (patch)
treee95be6e66db504ed06d00b72c579565bab873277 /app/source/Cplt/Utils/IO/TslRobinIntegration.hpp
parent2cf952088d375ac8b2f45b144462af0953436cff (diff)
Restructure project
Diffstat (limited to 'app/source/Cplt/Utils/IO/TslRobinIntegration.hpp')
-rw-r--r--app/source/Cplt/Utils/IO/TslRobinIntegration.hpp78
1 files changed, 78 insertions, 0 deletions
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 <Cplt/Utils/IO/DataStream.hpp>
+#include <Cplt/Utils/IO/Helper.hpp>
+
+#include <tsl/robin_map.h>
+#include <tsl/robin_set.h>
+#include <type_traits>
+
+namespace DataStreamAdapters {
+template <class TKeyAdapter = void, class TValueAdapter = void>
+struct TslRobinMap
+{
+ template <class TKey, class TValue>
+ static void ReadFromDataStream(InputDataStream& stream, tsl::robin_map<TKey, TValue>& map)
+ {
+ static_assert(std::is_default_constructible_v<TValue>);
+ static_assert(std::is_move_constructible_v<TValue>);
+
+ uint64_t size;
+ stream.Read(size);
+ map.reserve(size);
+
+ for (uint64_t i = 0; i < size; ++i) {
+ TKey key;
+ ReadHelper<TKeyAdapter>(stream, key);
+
+ TValue value;
+ ReadHelper<TValueAdapter>(stream, value);
+
+ map.insert(std::move(key), std::move(value));
+ }
+ }
+
+ template <class TKey, class TValue>
+ static void WriteToDataStream(OutputDataStream& stream, const tsl::robin_map<TKey, TValue>& map)
+ {
+ stream.Write((uint64_t)map.size());
+
+ for (auto it = map.begin(); it != map.end(); ++it) {
+ WriteHelper<TKeyAdapter>(stream, it.key());
+ WriteHelper<TValueAdapter>(stream, it.value());
+ }
+ }
+};
+
+template <class TAdapter = void>
+struct TslRobinSet
+{
+ template <class TElement>
+ static void ReadFromDataStream(InputDataStream& stream, tsl::robin_set<TElement>& set)
+ {
+ static_assert(std::is_default_constructible_v<TElement>);
+ static_assert(std::is_move_constructible_v<TElement>);
+
+ uint64_t size;
+ stream.Read(size);
+ set.reserve(size);
+
+ for (uint64_t i = 0; i < size; ++i) {
+ TElement element;
+ ReadHelper<TAdapter>(stream, element);
+
+ set.insert(std::move(element));
+ }
+ }
+
+ template <class TElement>
+ static void WriteToDataStream(OutputDataStream& stream, const tsl::robin_set<TElement>& set)
+ {
+ stream.Write((uint64_t)set.size());
+
+ for (auto& element : set) {
+ WriteHelper<TAdapter>(stream, element);
+ }
+ }
+};
+} // namespace DataStreamAdapters