Note
This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.
rustworkx.graph_union#
- graph_union(first, second, /, merge_nodes=False, merge_edges=False)#
Return a new PyGraph by forming a union from two input PyGraph objects
The algorithm in this function operates in three phases:
Add all the nodes from
secondintofirst. operates in \(\mathcal{O}(n_2)\), with \(n_2\) being number of nodes insecond.Merge nodes from
secondoverfirstgiven that:The
merge_nodesisTrue. operates in \(\mathcal{O}(n_1 n_2)\), with \(n_1\) being the number of nodes infirstand \(n_2\) the number of nodes insecondThe respective node in
secondandfirstshare the same weight/data payload.
Adds all the edges from
secondtofirst. If themerge_edgesparameter isTrueand the respective edge insecondandfirstshare the same weight/data payload they will be merged together.
- Parameters:
first (PyGraph) – The first undirected graph object
second (PyGraph) – The second undirected graph object
merge_nodes (bool) – If set to
Truenodes will be merged betweensecondandfirstif the weights are equal. Default:False.merge_edges (bool) – If set to
Trueedges will be merged betweensecondandfirstif the weights are equal. Default:False.
- Returns:
A new PyGraph object that is the union of
secondandfirst. It’s worth noting the weight/data payload objects are passed by reference fromfirstandsecondto this new object.- Return type: