From 4e3600d383b48a6d5eb487b0f8e331d3ae8d30bb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Tr=C3=A1vn=C3=AD=C4=8Dek?= <jan.travnicek@fit.cvut.cz>
Date: Mon, 10 Jan 2022 10:08:47 +0100
Subject: [PATCH] algo: use ext containers

---
 .../automaton/simplify/MinimizeVerbose.cpp    |  2 +-
 .../src/automaton/simplify/MinimizeVerbose.h  | 24 +++++++++----------
 .../src/minimum_cut/FordFulkerson.cpp         |  8 +++----
 .../src/minimum_cut/FordFulkerson.hpp         |  6 ++---
 .../minimum_cut/FordFulkersonTest.cpp         |  4 ++--
 5 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/alib2algo/src/automaton/simplify/MinimizeVerbose.cpp b/alib2algo/src/automaton/simplify/MinimizeVerbose.cpp
index f59f1c9992..c857089fec 100644
--- a/alib2algo/src/automaton/simplify/MinimizeVerbose.cpp
+++ b/alib2algo/src/automaton/simplify/MinimizeVerbose.cpp
@@ -3,7 +3,7 @@
 
 namespace {
 
-auto MinimizeVerboseNFA = registration::AbstractRegister < automaton::simplify::MinimizeVerbose, ext::vector < ext::map < std::pair < DefaultStateType, DefaultStateType >, ext::map < DefaultSymbolType, DefaultStateType > > >, const automaton::DFA < > & > ( automaton::simplify::MinimizeVerbose::minimize, "dfa" ).setDocumentation (
+auto MinimizeVerboseNFA = registration::AbstractRegister < automaton::simplify::MinimizeVerbose, ext::vector < ext::map < ext::pair < DefaultStateType, DefaultStateType >, ext::map < DefaultSymbolType, DefaultStateType > > >, const automaton::DFA < > & > ( automaton::simplify::MinimizeVerbose::minimize, "dfa" ).setDocumentation (
 "Minimizes deterministic finite autmaton, also reports the middle steps of the computation.\n\
 \n\
 @param dfa deterministic finite automaton to minimize.\n\
diff --git a/alib2algo/src/automaton/simplify/MinimizeVerbose.h b/alib2algo/src/automaton/simplify/MinimizeVerbose.h
index cc70461d49..53f12d34b0 100644
--- a/alib2algo/src/automaton/simplify/MinimizeVerbose.h
+++ b/alib2algo/src/automaton/simplify/MinimizeVerbose.h
@@ -52,16 +52,16 @@ public:
 	 * @return trace of minimisation of the automaton
 	 */
 	template < class SymbolType, class StateType >
-	static ext::vector < ext::map < std::pair < StateType, StateType >, ext::map < SymbolType, StateType > > > minimize(const automaton::DFA < SymbolType, StateType >& dfa );
+	static ext::vector < ext::map < ext::pair < StateType, StateType >, ext::map < SymbolType, StateType > > > minimize(const automaton::DFA < SymbolType, StateType >& dfa );
 
 private:
 	template < class SymbolType, class StateType >
-	static ext::map < std::pair < StateType, StateType >, ext::map < SymbolType, StateType > > print_progress ( const ext::map<std::pair<StateType, ext::set<std::pair<SymbolType, StateType> > >, ext::set<StateType> >& minimizedTransitionFunction);
+	static ext::map < ext::pair < StateType, StateType >, ext::map < SymbolType, StateType > > print_progress ( const ext::map<ext::pair<StateType, ext::set<ext::pair<SymbolType, StateType> > >, ext::set<StateType> >& minimizedTransitionFunction);
 };
 
 template < class SymbolType, class StateType >
-ext::vector < ext::map < std::pair < StateType, StateType >, ext::map < SymbolType, StateType > > > MinimizeVerbose::minimize(const automaton::DFA < SymbolType, StateType >& dfa ) {
-	ext::vector < ext::map < std::pair < StateType, StateType >, ext::map < SymbolType, StateType > > > res;
+ext::vector < ext::map < ext::pair < StateType, StateType >, ext::map < SymbolType, StateType > > > MinimizeVerbose::minimize(const automaton::DFA < SymbolType, StateType >& dfa ) {
+	ext::vector < ext::map < ext::pair < StateType, StateType >, ext::map < SymbolType, StateType > > > res;
 
 	ext::map<StateType, ext::map<SymbolType, StateType > > refactor;
 
@@ -72,7 +72,7 @@ ext::vector < ext::map < std::pair < StateType, StateType >, ext::map < SymbolTy
 		refactor[transition.first.first].insert(std::make_pair(transition.first.second, transition.second));
 
 	ext::map<StateType, StateType> toEquivalentStates; //original state to equivalent state
-	ext::map<std::pair<StateType, ext::set<std::pair<SymbolType, StateType> > >, ext::set<StateType> > minimizedTransitionFunction; //mapped to the original state
+	ext::map<ext::pair<StateType, ext::set<ext::pair<SymbolType, StateType> > >, ext::set<StateType> > minimizedTransitionFunction; //mapped to the original state
 
 	const StateType *firstFinal = nullptr;
 	const StateType *firstNonfinal = nullptr;
@@ -92,12 +92,12 @@ ext::vector < ext::map < std::pair < StateType, StateType >, ext::map < SymbolTy
 	while ( true ) {
 		for(const std::pair<const StateType, ext::map<SymbolType, StateType> >& transition : refactor) {
 			const StateType& from = toEquivalentStates.find(transition.first)->second;
-			ext::set<std::pair<SymbolType, StateType> > transitionFunction;
+			ext::set<ext::pair<SymbolType, StateType> > transitionFunction;
 
 			for(const std::pair<const SymbolType, StateType> & transitionFromState : transition.second)
-				transitionFunction.insert(std::make_pair(transitionFromState.first, toEquivalentStates.find(transitionFromState.second)->second));
+				transitionFunction.insert(ext::make_pair(transitionFromState.first, toEquivalentStates.find(transitionFromState.second)->second));
 
-			minimizedTransitionFunction[std::make_pair(from, transitionFunction)].insert(transition.first);
+			minimizedTransitionFunction[ext::make_pair(from, transitionFunction)].insert(transition.first);
 		}
 
 		res.push_back ( print_progress ( minimizedTransitionFunction) );
@@ -108,7 +108,7 @@ ext::vector < ext::map < std::pair < StateType, StateType >, ext::map < SymbolTy
 		prevSize = minimizedTransitionFunction.size();
 		toEquivalentStates.clear();
 
-		for(const std::pair<const std::pair<StateType, ext::set<std::pair<SymbolType, StateType> > >, ext::set<StateType> >& transition : minimizedTransitionFunction)
+		for(const std::pair<const ext::pair<StateType, ext::set < ext::pair<SymbolType, StateType> > >, ext::set<StateType> >& transition : minimizedTransitionFunction)
 			for(const StateType& target : transition.second)
 				toEquivalentStates.insert(std::make_pair(target, *(transition.second.begin())));
 
@@ -121,17 +121,17 @@ ext::vector < ext::map < std::pair < StateType, StateType >, ext::map < SymbolTy
 #define RESETSS(x) {(x).clear(); (x).str("");}
 
 template < class SymbolType, class StateType >
-ext::map<std::pair<StateType, StateType>, ext::map<SymbolType, StateType>> MinimizeVerbose::print_progress ( const ext::map<std::pair<StateType, ext::set<std::pair<SymbolType, StateType> > >, ext::set<StateType> >& minimizedTransitionFunction) {
+ext::map<ext::pair<StateType, StateType>, ext::map<SymbolType, StateType>> MinimizeVerbose::print_progress ( const ext::map<ext::pair<StateType, ext::set<ext::pair<SymbolType, StateType> > >, ext::set<StateType> >& minimizedTransitionFunction) {
 	/* need to restruct this first so we have table like:	orig state | new state | trans_symb_1 | trans_symb_2 | ... | trans_symb_n */
 	// we surely have DFA here (transition map hence)
-	ext::map<std::pair<StateType, StateType>, ext::map<SymbolType, StateType>> printMap;
+	ext::map<ext::pair<StateType, StateType>, ext::map<SymbolType, StateType>> printMap;
 	for(const auto& kv: minimizedTransitionFunction) {
 		for(const auto& state : kv.second) {
 			ext::map<SymbolType, StateType> stateTransMap;
 			for(const auto& transition : kv.first.second) {
 				stateTransMap.insert(std::make_pair(transition.first, transition.second));
 			}
-			printMap.insert(std::make_pair(std::make_pair(state, kv.first.first), stateTransMap));
+			printMap.insert(std::make_pair(ext::make_pair(state, kv.first.first), stateTransMap));
 		}
 	}
 	return printMap;
diff --git a/alib2graph_algo/src/minimum_cut/FordFulkerson.cpp b/alib2graph_algo/src/minimum_cut/FordFulkerson.cpp
index 2d77c97847..aa386216a4 100644
--- a/alib2graph_algo/src/minimum_cut/FordFulkerson.cpp
+++ b/alib2graph_algo/src/minimum_cut/FordFulkerson.cpp
@@ -43,7 +43,7 @@ static Cut fordfulkerson_impl_dir(const DirectedGraph &graph,
   // mark nodes, which are reachable from source
   ext::unordered_map<node::Node, int> state;
   std::queue<node::Node> open;
-  ext::vector<std::pair<node::Node, node::Node>> candidates;
+  ext::vector<ext::pair<node::Node, node::Node>> candidates;
   for (const node::Node &node : graph.getNodes())
     state[node] = 0;
   state[source] = 1;
@@ -70,7 +70,7 @@ static Cut fordfulkerson_impl_dir(const DirectedGraph &graph,
   }
 
   // cut are those edges, which lead from nodes reachable from source to nodes unreachable from source
-  for (const std::pair<node::Node, node::Node> & edge : candidates) {
+  for (const ext::pair<node::Node, node::Node> & edge : candidates) {
     if ((state[edge.first] == 1 && state[edge.second] == 0)
         || (state[edge.first] == 0 && state[edge.second] == 1))
       cut.insert(edge);
@@ -91,7 +91,7 @@ static Cut fordfulkerson_impl_undir(const UndirectedGraph &ugraph,
   // mark nodes, which are reachable from source
   ext::unordered_map<node::Node, int> state;
   std::queue<node::Node> open;
-  ext::vector<std::pair<node::Node, node::Node>> candidates;
+  ext::vector<ext::pair<node::Node, node::Node>> candidates;
   for (const node::Node &node : ugraph.getNodes())
     state[node] = 0;
   state[source] = 1;
@@ -110,7 +110,7 @@ static Cut fordfulkerson_impl_undir(const UndirectedGraph &ugraph,
   }
 
   // cut are those edges, which lead from nodes reachable from source to nodes unreachable from source
-  for (const std::pair<node::Node, node::Node> & edge : candidates) {
+  for (const ext::pair<node::Node, node::Node> & edge : candidates) {
     if ((state[edge.first] == 1 && state[edge.second] == 0)
         || (state[edge.first] == 0 && state[edge.second] == 1))
       cut.insert(edge);
diff --git a/alib2graph_algo/src/minimum_cut/FordFulkerson.hpp b/alib2graph_algo/src/minimum_cut/FordFulkerson.hpp
index 87a4405b74..80951a7616 100644
--- a/alib2graph_algo/src/minimum_cut/FordFulkerson.hpp
+++ b/alib2graph_algo/src/minimum_cut/FordFulkerson.hpp
@@ -10,8 +10,8 @@
 
 namespace std {
 template<>
-struct hash<std::pair<node::Node, node::Node> > {
-  std::size_t operator()(const std::pair<node::Node, node::Node> &p) const {
+struct hash<ext::pair<node::Node, node::Node> > {
+  std::size_t operator()(const ext::pair<node::Node, node::Node> &p) const {
     return std::hash<std::string>()(ext::to_string(p.first) + ext::to_string(p.second));
   }
 };
@@ -23,7 +23,7 @@ namespace graph {
 
 namespace minimum_cut {
 
-typedef ext::unordered_set<std::pair<node::Node, node::Node> > Cut;
+typedef ext::unordered_set<ext::pair<node::Node, node::Node> > Cut;
 
 // Old implementation without templates
 using UndirectedGraph = graph::UndirectedGraph<node::Node, edge::CapacityEdge<node::Node, int>>;
diff --git a/alib2graph_algo/test-src/minimum_cut/FordFulkersonTest.cpp b/alib2graph_algo/test-src/minimum_cut/FordFulkersonTest.cpp
index cf211701bc..e475ea3c29 100644
--- a/alib2graph_algo/test-src/minimum_cut/FordFulkersonTest.cpp
+++ b/alib2graph_algo/test-src/minimum_cut/FordFulkersonTest.cpp
@@ -126,7 +126,7 @@ void testDirNetwork(unsigned netID, const Type1 *netDef, const Type2 cutDef, uns
 
 	CHECK ( cutSize == cut.size ( ) );
 	for (i = 0; i < cutSize; i++) {
-		CHECK(cut.find(std::make_pair(id2node[cutDef[i].node1ID], id2node[cutDef[i].node2ID])) != cut.end());
+		CHECK(cut.find(ext::make_pair(id2node[cutDef[i].node1ID], id2node[cutDef[i].node2ID])) != cut.end());
 	}
 }
 
@@ -156,7 +156,7 @@ void testUndirNetwork(unsigned netID, const Type1 *netDef, const Type2 cutDef, u
 
 	CHECK (cutSize == cut.size ( ) );
 	for (i = 0; i < cutSize; i++) {
-		CHECK(cut.find(std::make_pair(id2node[cutDef[i].node1ID], id2node[cutDef[i].node2ID])) != cut.end());
+		CHECK(cut.find(ext::make_pair(id2node[cutDef[i].node1ID], id2node[cutDef[i].node2ID])) != cut.end());
 	}
 }
 
-- 
GitLab