From cc4f8f09e529c8d281b5b613508e40b1f10949ed Mon Sep 17 00:00:00 2001 From: Glauber Costa Date: Thu, 19 Feb 2015 14:33:15 -0500 Subject: [PATCH] parser: disk_hash type Signed-off-by: Glauber Costa Reviewed-by: Nadav Har'El --- sstables/sstables.cc | 28 ++++++++++++++++++++++++++++ sstables/types.hh | 6 ++++++ 2 files changed, 34 insertions(+) diff --git a/sstables/sstables.cc b/sstables/sstables.cc index 24b908c3f4..a232209869 100644 --- a/sstables/sstables.cc +++ b/sstables/sstables.cc @@ -178,6 +178,34 @@ future<> parse(file_input_stream& in, disk_array& arr) { }); } +template +future<> parse(file_input_stream& in, Size& len, std::unordered_map& map) { + auto count = make_lw_shared(); + auto eos = [len, count] { return len == *count; }; + return do_until(eos, [len, count, &in, &map] { + struct kv { + Key key; + Value value; + }; + ++*count; + + auto el = std::make_unique(); + auto f = parse(in, el->key, el->value); + return f.then([el = std::move(el), &map] { + map.emplace(el->key, el->value); + }); + }); +} + +template +future<> parse(file_input_stream& in, disk_hash& h) { + auto w = std::make_unique(); + auto f = parse(in, *w); + return f.then([&in, &h, w = std::move(w)] { + return parse(in, *w, h.map); + }); +} + const bool sstable::has_component(component_type f) { return _components.count(f); } diff --git a/sstables/types.hh b/sstables/types.hh index 1a378ecd0b..af3f5ee68f 100644 --- a/sstables/types.hh +++ b/sstables/types.hh @@ -1,5 +1,7 @@ #pragma once +#include "core/enum.hh" + namespace sstables { // Some in-disk structures have an associated integer (of varying sizes) that @@ -22,4 +24,8 @@ struct disk_array { std::vector elements; }; +template +struct disk_hash { + std::unordered_map> map; +}; }