9 namespace graph_algorithm
15 return ERR(
"graph is a nullptr");
18 igraph_vector_int_t membership;
19 if (
auto res = igraph_vector_int_init(&membership, 0); res != IGRAPH_SUCCESS)
21 return ERR(igraph_strerror(res));
24 const igraph_t* i_graph = graph->
get_graph();
25 if (
auto res = igraph_connected_components(i_graph, &membership,
nullptr,
nullptr, strong ? IGRAPH_STRONG : IGRAPH_WEAK); res != IGRAPH_SUCCESS)
27 igraph_vector_int_destroy(&membership);
28 return ERR(igraph_strerror(res));
31 u32 num_vertices = igraph_vcount(i_graph);
32 std::map<u32, std::set<u32>> components_raw;
34 for (
i32 i = 0; i < num_vertices; i++)
36 components_raw[VECTOR(membership)[i]].insert(i);
39 std::vector<std::vector<u32>> components;
40 for (
auto& [_, members] : components_raw)
42 if (members.size() < min_size)
47 components.push_back(std::vector<u32>(members.begin(), members.end()));
50 igraph_vector_int_destroy(&membership);
52 return OK(components);
A directed graph corresponding to a netlist.
igraph_t * get_graph() const
Get the graph object of the netlist graph.
This file contains functions related to graph components.
Result< std::vector< std::vector< u32 > > > get_connected_components(const NetlistGraph *graph, bool strong, u32 min_size=0)
Compute the (strongly) connected components of the specified graph.
This file contains the class that holds a netlist graph.