Skip to content

Commit

Permalink
made get_graph const
Browse files Browse the repository at this point in the history
  • Loading branch information
SJulianS committed May 23, 2024
1 parent 539aeaa commit f85466c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion plugins/graph_algorithm/src/algorithms/components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
13 changes: 9 additions & 4 deletions plugins/graph_algorithm/src/netlist_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f85466c

Please sign in to comment.