Skip to content

Commit

Permalink
explicitly normalising undirected edges
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfischer2781 committed Jul 29, 2018
1 parent b267e75 commit 2c440f4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion graphi/types/bounded.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _ensure_bounds(self):
except TypeError as err:
raise ValueError('cannot bound %r to %r: %s' % (value, self.value_bound, err))
if self.undirected:
blacklist = {{tail, head} for tail, head in blacklist}
blacklist = {(tail, head) if hash(head) > hash(tail) else (head, tail) for tail, head in blacklist}
for tail, head in blacklist:
del self._graph[tail:head]

Expand Down
3 changes: 2 additions & 1 deletion graphi/types/undirected.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def __init__(self, start, stop, step=None):
# start and stop may be unsortable,
# but the interface guarantees that they
# are hashable
start, stop = {start, stop}
if hash(start) > hash(stop):
start, stop = stop, start
super(UndirectedEdge, self).__init__(start, stop, step)

def __eq__(self, other):
Expand Down

0 comments on commit 2c440f4

Please sign in to comment.