diff --git a/src/main.cpp b/src/main.cpp index 7595e48..bf6addd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -116,18 +116,8 @@ struct FindStringVisitor : boost::static_visitor { } } - bool is_prefix_path (std::string_view curr_element) const { - if (path.size() + 1 > search.size()) - return false; - - return std::equal(path.cbegin(), path.cend(), search.cbegin()) and (search[path.size()] == curr_element); - } - bool is_path_found() const { - if (path.size() != search.size()) - return false; - - return std::equal(path.cbegin(), path.cend(), search.cbegin()); + return search.size() == search_match_count; } std::string_view operator() (long long value) { @@ -141,7 +131,7 @@ struct FindStringVisitor : boost::static_visitor { return {}; } - std::string_view operator() (const std::vector& value) { + std::string_view operator() (const std::vector&) { return {}; } @@ -149,17 +139,16 @@ struct FindStringVisitor : boost::static_visitor { if (is_path_found()) return {}; - for (const auto& item : value) { - if (is_prefix_path(item.first)) { - path.push_back(item.first); - return boost::apply_visitor(*this, item.second); - } - } - return {}; + auto it_found = value.find(search[search_match_count]); + if (value.end() == it_found) + return {}; + + ++search_match_count; + return boost::apply_visitor(*this, it_found->second); } - std::vector path; std::vector search; + std::size_t search_match_count{0}; }; std::vector> collect_hashes (std::string_view hashes) {