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.PyDiGraph.remove_node_retain_edges_by_key#

PyDiGraph.remove_node_retain_edges_by_key(node, /, key=None, *, use_outgoing=False)#

Remove a node from the graph and add edges from predecessors to successors in cases where an incoming and outgoing edge have the same weight by Python object equality.

This function has a minimum time complexity of \(\mathcal O(e_i + e_o)\), where \(e_i\) is the number of incoming edges and \(e_o\) the number of outgoing edges (the full complexity depends on the number of new edges to be created).

Edges will be added between all pairs of predecessor and successor nodes that have equal weights. As a consequence, any weight which appears only on predecessor edges will not appear in the output, as there are no successors to pair it with.

If there are multiple edges with the same weight, the exact Python object used on the new edges is an implementation detail and may change. The only guarantees are that it will be deterministic for a given graph, and that it will be drawn from the incoming edges if use_outgoing=False (the default) or from the outgoing edges if use_outgoing=True.

Parameters:
  • node (int) – The index of the node to remove. If the index is not present in the graph it will be ignored and this function will have no effect.

  • key – A callable Python object that is called once for each connected edge, to generate the “key” for that weight. It is passed exactly one argument positionally (the weight of the edge), and should return a Python object that is hashable and implements equality checking with all other relevant keys. If not given, the edge weights will be used directly.

  • use_outgoing (bool) – If False (default), the new edges will use the weight from one of the incoming edges. If True, they will instead use a weight from one of the outgoing edges.