diff --git a/persistent-data/data-structures/btree_key_value_extractor.h b/persistent-data/data-structures/btree_key_value_extractor.h new file mode 100644 index 0000000..40b7f7b --- /dev/null +++ b/persistent-data/data-structures/btree_key_value_extractor.h @@ -0,0 +1,39 @@ +#ifndef PERSISTENT_DATA_DATA_STRUCTURES_BTREE_KEY_VALUE_EXTRACTOR_H +#define PERSISTENT_DATA_DATA_STRUCTURES_BTREE_KEY_VALUE_EXTRACTOR_H + +#include "persistent-data/data-structures/btree_damage_visitor.h" +#include + +namespace persistent_data { + namespace btree_detail { + template + class key_value_extractor { + typedef typename std::map MapType; + public: + key_value_extractor(MapType &map): map_(map) { + } + + virtual ~key_value_extractor() { + } + + virtual void visit(btree_path const &path, ValueType const &v) { + map_.insert(std::make_pair(path.back(), v)); + } + private: + MapType &map_; + }; + + template + void btree_extract_key_values(btree const &tree, + std::map &map) { + typedef key_value_extractor KeyValueExtractor; + KeyValueExtractor kve(map); + noop_damage_visitor noop_dv; + btree_detail::btree_damage_visitor + v(kve, noop_dv); + tree.visit_depth_first(v); + } + } +} + +#endif