Commit d2e8ce3a authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Implement Graph.edge method

parent 9e353964
......@@ -691,6 +691,26 @@ class Graph(object):
return v
def edge(self, s, t, all_edges=False):
"""Return the edge from vertex ``s`` to ``t``, if it exists. If
``all_edges=True`` then a list is returned with all the parallel edges
from ``s`` to ``t``, otherwise only one edge is returned.
This operation will take :math:`O(k(s))` time, where :math:`k(s)` is the
out-degree of vertex :math:`s`.
s = self.vertex(int(s))
t = self.vertex(int(t))
edges = []
for e in s.out_edges():
if == t:
if not all_edges:
return e
if all_edges:
return edges
return None
def edges(self):
"""Return an iterator over the edges."""
return libcore.get_edges(weakref.ref(self.__graph))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment