MCPcopy Index your code
hub / github.com/clips/pattern / redirect

Function redirect

pattern/graph/__init__.py:1057–1070  ·  view source on GitHub ↗

Connects all of node1's edges to node2 and unlinks node1.

(graph, node1, node2)

Source from the content-addressed store, hash-verified

1055 pass
1056
1057def redirect(graph, node1, node2):
1058 """ Connects all of node1's edges to node2 and unlinks node1.
1059 """
1060 if not isinstance(node1, Node):
1061 node1 = graph[node1]
1062 if not isinstance(node2, Node):
1063 node2 = graph[node2]
1064 for e in graph.edges:
1065 if node1 in (e.node1, e.node2):
1066 if e.node1 == node1 and e.node2 != node2:
1067 graph._add_edge_copy(e, node1=node2, node2=e.node2)
1068 if e.node2 == node1 and e.node1 != node2:
1069 graph._add_edge_copy(e, node1=e.node1, node2=node2)
1070 unlink(graph, node1)
1071
1072def cut(graph, node):
1073 """ Unlinks the given node, but keeps edges intact by connecting the surrounding nodes.

Callers

nothing calls this directly

Calls 2

unlinkFunction · 0.85
_add_edge_copyMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…