diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-05-10 03:36:59 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2026-05-10 03:36:59 -0300 |
| commit | 2864398c7b723c1d43166d422ea7028ef33cf9e3 (patch) | |
| tree | ec63cd647239612167c36e521610f69023ed9303 /include/InMemoryBackend.h | |
| parent | 7ffd4d99bbb8e358c6694c27c7ff859967872ece (diff) | |
| download | RNT-2864398c7b723c1d43166d422ea7028ef33cf9e3.tar.gz RNT-2864398c7b723c1d43166d422ea7028ef33cf9e3.zip | |
sqlite backend with actual pagination
Diffstat (limited to '')
| -rw-r--r-- | include/InMemoryBackend.h | 43 |
1 files changed, 43 insertions, 0 deletions
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 <cstdint> +#include <optional> +#include <string> +#include <unordered_map> +#include <vector> + +/** + * @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<uint8_t> value) override; + std::optional<std::vector<uint8_t>> Get(const std::string& hash) override; + void LinkTuple(const std::vector<std::string>& relation_path, + const std::string& tuple_hash) override; + std::vector<std::string> TupleHashes(const std::vector<std::string>& relation_path, + std::size_t offset, + std::size_t limit) override; + + private: + std::unordered_map<std::string, std::vector<uint8_t>> kv_; + std::unordered_map<std::string, std::vector<std::string>> index_; + + static std::string PathKey(const std::vector<std::string>& path); + }; +} |
