1    class Edge:
2        '''
3        Class for representing edge structure for a graph.
4        '''
5        __slots__ = '_origin', '_destination', '_element'
6
7        def __init__(self, u, v, x):
8            '''
9            Do not call constructor directly. Use Graph's insert_edge(x).
10           '''
11           self._origin = u
12           self._destination = v
13           self._element = x
14        def endPoints(self):
15           '''
16           Return (u,v) tuple for vertices u and v.
17           '''
18           return (self._origin, self._destination)
19        def opposite(self, v):
20           '''
21           Return the vertex that is opposite v on this edge.
22           '''
23           return self._destination if self._origin == v else self._origin
24        def element(self):
25           '''
26           Return element associated with this edge.
27           '''
28           return self._element
29        def __hash__(self):
30           '''
31           will allow edge to be a map/set key
32           '''
33           return hash(id(self))
