MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / _add_one_edge

Function _add_one_edge

cpp_easygraph/classes/graph.cpp:229–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

227}
228
229void _add_one_edge(Graph& self, py::object u_of_edge, py::object v_of_edge, py::object edge_attr) {
230 node_t u, v;
231 if (!self.node_to_id.contains(u_of_edge)) {
232 u = _add_one_node(self, u_of_edge);
233 } else {
234 u = self.node_to_id[u_of_edge].cast<node_t>();
235 }
236 if (!self.node_to_id.contains(v_of_edge)) {
237 v = _add_one_node(self, v_of_edge);
238 } else {
239 v = self.node_to_id[v_of_edge].cast<node_t>();
240 }
241 py::list items = py::list(edge_attr.attr("items")());
242 self.adj[u][v] = node_attr_dict_factory();
243 self.adj[v][u] = node_attr_dict_factory();
244 for (int i = 0; i < len(items); i++) {
245 py::tuple kv = items[i].cast<py::tuple>();
246 py::object pkey = kv[0];
247 std::string weight_key = weight_to_string(pkey);
248 weight_t value = kv[1].cast<weight_t>();
249 self.adj[u][v].insert(std::make_pair(weight_key, value));
250 self.adj[v][u].insert(std::make_pair(weight_key, value));
251 }
252}
253
254py::object Graph_add_edge(py::args args, py::kwargs kwargs) {
255 Graph& self = args[0].cast<Graph&>();

Callers 4

Graph_add_edgeFunction · 0.85
Graph_add_edgesFunction · 0.85
Graph_add_weighted_edgeFunction · 0.85
Graph_nodes_subgraphFunction · 0.85

Calls 2

_add_one_nodeFunction · 0.85
weight_to_stringFunction · 0.85

Tested by

no test coverage detected