rustworkx.digraph_union#
- digraph_union(first, second, /, merge_nodes=False, merge_edges=False)#
Return a new PyDiGraph by forming a union from two input PyDiGraph objects
The algorithm in this function operates in three phases:
Add all the nodes from
second
intofirst
. operates in \(\mathcal{O}(n_2)\), with \(n_2\) being number of nodes insecond
.Merge nodes from
second
overfirst
given that:The
merge_nodes
isTrue
. operates in \(\mathcal{O}(n_1 n_2)\), with \(n_1\) being the number of nodes infirst
and \(n_2\) the number of nodes insecond
The respective node in
second
andfirst
share the same weight/data payload.
Adds all the edges from
second
tofirst
. If themerge_edges
parameter isTrue
and the respective edge insecond
andfirst
share the same weight/data payload they will be merged together.
- Parameters:
first (PyDiGraph) – The first directed graph object
second (PyDiGraph) – The second directed graph object
merge_nodes (bool) – If set to
True
nodes will be merged betweensecond
andfirst
if the weights are equal. Default:False
.merge_edges (bool) – If set to
True
edges will be merged betweensecond
andfirst
if the weights are equal. Default:False
.
- Returns:
A new PyDiGraph object that is the union of
second
andfirst
. It’s worth noting the weight/data payload objects are passed by reference fromfirst
andsecond
to this new object.- Return type: