From f4b2027868c9733bbbbcb4c5ec6d5462a8447e5d Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 21 Jan 2020 22:49:30 +0100 Subject: Separate to cpp files --- bnf.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 bnf.cpp (limited to 'bnf.cpp') diff --git a/bnf.cpp b/bnf.cpp new file mode 100644 index 0000000..1efb459 --- /dev/null +++ b/bnf.cpp @@ -0,0 +1,21 @@ +#include "bnf.h" + +std::map> Reverse(BNF bnf){ + std::map> result; + + for (const auto& [from, to] : bnf) { + for (const auto& list : to) { + for (const auto& element : list) { + auto i{result.find(element)}; + if (i != result.end()) // already present + i->second.insert(from); + else // new element + result.emplace(element, std::set{from}); + } + } + } + + return result; +} + + -- cgit v1.2.3