MCPcopy Create free account
hub / github.com/Persper/code-analytics / remove_edges_of_node

Function remove_edges_of_node

persper/graphs/call_graph/utils.py:20–45  ·  view source on GitHub ↗

Remove edges of n, but keep the node itself in the graph >>> G3 = nx.DiGraph() >>> G3.add_path([0, 1, 2, 3, 4]) >>> remove_edges_of_node(G3, 2) >>> G3.nodes() [0, 1, 2, 3, 4] >>> G3.edges() [(0, 1), (3, 4)]

(G, n, in_edges=True, out_edges=True)

Source from the content-addressed store, hash-verified

18
19
20def remove_edges_of_node(G, n, in_edges=True, out_edges=True):
21 """Remove edges of n, but keep the node itself in the graph
22
23 >>> G3 = nx.DiGraph()
24 >>> G3.add_path([0, 1, 2, 3, 4])
25 >>> remove_edges_of_node(G3, 2)
26 >>> G3.nodes()
27 [0, 1, 2, 3, 4]
28 >>> G3.edges()
29 [(0, 1), (3, 4)]
30
31 """
32 try:
33 nbrs = G._succ[n]
34 except KeyError: # NetworkXError if not in self
35 # raise NetworkXError("The node %s is not in the digraph."%(n, ))
36 print("The node %s is not in the digraph." % n)
37 return
38 if out_edges:
39 for u in nbrs:
40 del G._pred[u][n]
41 G._succ[n] = {}
42 if in_edges:
43 for u in G._pred[n]:
44 del G._succ[u][n]
45 G._pred[n] = {}

Callers 2

update_call_graph_javaFunction · 0.90
update_call_graph_cFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected