MyGraph MyGraph::graph_union(const MyGraph& g2) const { MyGraph output = copyGraph(); graph_hashmap::const_iterator g2_it = g2.thegraph.begin(); while(g2_it != this->thegraph.end()){ if ( output.thegraph.find(g2_it->first) == output.thegraph.end()) output.insertVertex(g2_it->first); //cycle through all the edges contained in the node hashmap node_hashmap::const_iterator node_iter = g2_it->second.begin(); while (node_iter != g2_it->second.end() ){ if (!output.areAdjacent(g2_it->first,node_iter->first)) output.insertEdge(g2_it->first,node_iter->first); *node_iter++; } *g2_it++; } return output; }
MyGraph MyGraph::graph_complement() const{ MyGraph output = copyGraph(); graph_hashmap::const_iterator g_iter = thegraph.begin(); my_set::const_iterator g2_iter; while (g_iter != thegraph.end()){ g2_iter = set_of_vertices.begin(); while ( g2_iter != set_of_vertices.end()){ if (strcmp(g_iter->first.c_str(),(*g2_iter).c_str()) ){ //avoid self-loops if( areAdjacent(g_iter->first, *g2_iter) ) output.removeEdge(g_iter->first, *g2_iter); else if (!output.areAdjacent(g_iter->first, *g2_iter)) output.insertEdge(g_iter->first, *g2_iter); } *g2_iter++; } *g_iter++; } return output; }