rustworkx.union#
- union(first, second, merge_nodes=False, merge_edges=False)[source]#
Return a new graph by forming a union from two input graph objects
The algorithm in this function operates in three phases:
1. Add all the nodes from
secondintofirst. operates in \(\mathcal{O}(n_2)\), with \(n_2\) being number of nodes insecond. 2. Merge nodes fromsecondoverfirstgiven 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 – The first graph object
second – The second 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 graph 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: