diff --git a/plugins/graph_algorithm/include/graph_algorithm/algorithms/components.h b/plugins/graph_algorithm/include/graph_algorithm/algorithms/components.h index 10387ae96d6..76202b039f3 100644 --- a/plugins/graph_algorithm/include/graph_algorithm/algorithms/components.h +++ b/plugins/graph_algorithm/include/graph_algorithm/algorithms/components.h @@ -46,6 +46,6 @@ namespace hal * @param[in] min_size - Minimal size of a connected component to be part of the result. Set to `0` to include all components. Defaults to `0`. * @returns A vector of strongly connected components on success, an error otherwise. */ - Result<std::vector<std::vector<u32>>> get_connected_components(NetlistGraph* graph, bool strong, u32 min_size = 0); + Result<std::vector<std::vector<u32>>> get_connected_components(const NetlistGraph* graph, bool strong, u32 min_size = 0); } // namespace graph_algorithm } // namespace hal \ No newline at end of file diff --git a/plugins/graph_algorithm/include/graph_algorithm/netlist_graph.h b/plugins/graph_algorithm/include/graph_algorithm/netlist_graph.h index b8e989559c3..5c968c9adf0 100644 --- a/plugins/graph_algorithm/include/graph_algorithm/netlist_graph.h +++ b/plugins/graph_algorithm/include/graph_algorithm/netlist_graph.h @@ -98,7 +98,7 @@ namespace hal * * @returns The graph object. */ - igraph_t* get_graph(); + igraph_t* get_graph() const; /** * Get the gates corresponding to the specified vertices. @@ -282,6 +282,7 @@ namespace hal Netlist* m_nl; igraph_t m_graph; + igraph_t* m_graph_ptr; std::unordered_map<u32, Gate*> m_nodes_to_gates; std::unordered_map<Gate*, u32> m_gates_to_nodes; }; diff --git a/plugins/graph_algorithm/src/algorithms/components.cpp b/plugins/graph_algorithm/src/algorithms/components.cpp index aad3d904d14..8f2115edd13 100644 --- a/plugins/graph_algorithm/src/algorithms/components.cpp +++ b/plugins/graph_algorithm/src/algorithms/components.cpp @@ -8,7 +8,7 @@ namespace hal { namespace graph_algorithm { - Result<std::vector<std::vector<u32>>> get_connected_components(NetlistGraph* graph, bool strong, u32 min_size) + Result<std::vector<std::vector<u32>>> get_connected_components(const NetlistGraph* graph, bool strong, u32 min_size) { if (graph == nullptr) { diff --git a/plugins/graph_algorithm/src/netlist_graph.cpp b/plugins/graph_algorithm/src/netlist_graph.cpp index d037024b273..b085c408c9d 100644 --- a/plugins/graph_algorithm/src/netlist_graph.cpp +++ b/plugins/graph_algorithm/src/netlist_graph.cpp @@ -16,6 +16,8 @@ namespace hal NetlistGraph::NetlistGraph(Netlist* nl, igraph_t&& graph, std::unordered_map<u32, Gate*>&& nodes_to_gates) : m_nl(nl), m_graph(std::move(graph)), m_nodes_to_gates(std::move(nodes_to_gates)) { + m_graph_ptr = &m_graph; + for (const auto& [node, gate] : m_nodes_to_gates) { if (gate) @@ -142,7 +144,9 @@ namespace hal } } - err = igraph_create(&(graph->m_graph), &edges, node_counter, IGRAPH_DIRECTED); + graph->m_graph_ptr = &(graph->m_graph); + err = igraph_create(graph->m_graph_ptr, &edges, node_counter, IGRAPH_DIRECTED); + igraph_vector_int_destroy(&edges); if (err != IGRAPH_SUCCESS) @@ -172,7 +176,8 @@ namespace hal graph->m_nodes_to_gates[node] = g; } - auto err = igraph_empty(&(graph->m_graph), node_counter, IGRAPH_DIRECTED); + graph->m_graph_ptr = &(graph->m_graph); + auto err = igraph_empty(graph->m_graph_ptr, node_counter, IGRAPH_DIRECTED); if (err != IGRAPH_SUCCESS) { return ERR(igraph_strerror(err)); @@ -201,9 +206,9 @@ namespace hal return m_nl; } - igraph_t* NetlistGraph::get_graph() + igraph_t* NetlistGraph::get_graph() const { - return &m_graph; + return m_graph_ptr; } Result<std::vector<Gate*>> NetlistGraph::get_gates_from_vertices(const std::vector<u32>& vertices) const