'Add an edge between u and v.
The nodes u and v will be automatically added if they are
not already in the graph.
Edge attributes can be specified with keywords or by directly
accessing the edge\'s attribute dictionary. See examples below.
Parameters
u, v : nodes
Nodes can be, for example, strings or numbers.
Nodes must be hashable (and not None) Python objects.
key : hashable identifier, optional (default=lowest unused integer)
Used to distinguish multiedges between a pair of nodes.
attr : keyword arguments, optional
Edge data (or labels or objects) can be assigned using
keyword arguments.
Returns
The edge key assigned to the edge.
See Also
add_edges_from : add a collection of edges
Notes
To replace/update edge data, use the optional key argument
to identify a unique edge.  Otherwise a new edge will be created.
NetworkX algorithms designed for weighted graphs cannot use
multigraphs directly because it is not clear how to handle
multiedge weights.  Convert to Graph using edge attribute
\'weight\' to enable weighted graph algorithms.
Default keys are generated using the method `new_edge_key()`.
This method can be overridden by subclassing the base class and
providing a custom `new_edge_key()` method.
Examples
The following all add the edge e=(1, 2) to graph G:
>>> G = nx.Graph()   # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> e = (1, 2)
>>> G.add_edge(1, 2)           # explicit two-node form
>>> G.add_edge(*e)             # single edge as tuple of two nodes
>>> G.add_edges_from( [(1, 2)] ) # add edges from iterable container
Associate data to edges using keywords:
>>> G.add_edge(1, 2, weight=3)
>>> G.add_edge(1, 2, key=0, weight=4)   # update data for key=0
>>> G.add_edge(1, 3, weight=7, capacity=15, length=342.7)'

def add_edge(self, u, v, key=None, **attr):

    if (u not in self._adj):
        self._adj[u] = self.adjlist_inner_dict_factory()
        self._node[u] = {}
    if (v not in self._adj):
        self._adj[v] = self.adjlist_inner_dict_factory()
        self._node[v] = {}
    if (key is None):
        key = self.new_edge_key(u, v)
    if (v in self._adj[u]):
        keydict = self._adj[u][v]
        datadict = keydict.get(key, self.edge_attr_dict_factory())
        datadict.update(attr)
        keydict[key] = datadict
    else:
        datadict = self.edge_attr_dict_factory()
        datadict.update(attr)
        keydict = self.edge_key_dict_factory()
        keydict[key] = datadict
        self._adj[u][v] = keydict
        self._adj[v][u] = keydict
    return key
