From 2864398c7b723c1d43166d422ea7028ef33cf9e3 Mon Sep 17 00:00:00 2001 From: Marcos Magueta Date: Sun, 10 May 2026 03:36:59 -0300 Subject: sqlite backend with actual pagination --- include/InMemoryBackend.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 include/InMemoryBackend.h (limited to 'include/InMemoryBackend.h') diff --git a/include/InMemoryBackend.h b/include/InMemoryBackend.h new file mode 100644 index 0000000..8f7f50a --- /dev/null +++ b/include/InMemoryBackend.h @@ -0,0 +1,43 @@ +#pragma once + +#include "Api.h" +#include "IStorageBackend.h" + +#include +#include +#include +#include +#include + +/** + * @file InMemoryBackend.h + * @brief In-process KV storage backend backed by unordered_maps. + */ + +namespace nt +{ + /** + * @interface InMemoryBackend + * @brief IStorageBackend implementation that keeps all data in process memory. + * + * Intended for unit tests where SQLite is not appropriate. Data does not + * survive process exit and is not thread-safe. + */ + class NT_API InMemoryBackend : public IStorageBackend + { + public: + std::string Put(std::vector value) override; + std::optional> Get(const std::string& hash) override; + void LinkTuple(const std::vector& relation_path, + const std::string& tuple_hash) override; + std::vector TupleHashes(const std::vector& relation_path, + std::size_t offset, + std::size_t limit) override; + + private: + std::unordered_map> kv_; + std::unordered_map> index_; + + static std::string PathKey(const std::vector& path); + }; +} -- cgit v1.2.3