Returns an unused key for edges between nodes `u` and `v`. The nodes `u` and `v` do not need to be already in the graph. Notes ----- In the standard MultiGraph class the new key is the number of existing edges between `u` and `v` (increased if necessary to e
(self, u, v)
| 80 | Graph.__init__(self, incoming_graph_data, **attr) |
| 81 | |
| 82 | def new_edge_key(self, u, v): |
| 83 | """Returns an unused key for edges between nodes `u` and `v`. |
| 84 | |
| 85 | The nodes `u` and `v` do not need to be already in the graph. |
| 86 | |
| 87 | Notes |
| 88 | ----- |
| 89 | In the standard MultiGraph class the new key is the number of existing |
| 90 | edges between `u` and `v` (increased if necessary to ensure unused). |
| 91 | The first edge will have key 0, then 1, etc. If an edge is removed |
| 92 | further new_edge_keys may not be in this order. |
| 93 | |
| 94 | Parameters |
| 95 | ---------- |
| 96 | u, v : nodes |
| 97 | |
| 98 | Returns |
| 99 | ------- |
| 100 | key : int |
| 101 | """ |
| 102 | try: |
| 103 | keydict = self._adj[u][v] |
| 104 | except KeyError: |
| 105 | return 0 |
| 106 | key = len(keydict) |
| 107 | while key in keydict: |
| 108 | key += 1 |
| 109 | return key |
| 110 | |
| 111 | def add_edge(self, u_for_edge, v_for_edge, key=None, **attr): |
| 112 | """Add an edge between u and v. |