Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/algoritmia/datastructures/digraphs/weightingfunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ class WeightingFunction(IMap, Callable): #[weighting
self._map = self.createMap(data)
self.symmetrical = symmetrical
if symmetrical:
duplicates = set()
for (u, v) in self._map.keys():
if (v, u) in self._map:
if self._map[u, v] != self._map[v, u]:
raise ValueError("{!r} is different from {!r}".format((u,v), (v,u)))
if v != u: del self._map[v, u]
if v != u and (u, v) not in duplicates:
duplicates.add((v, u))

for dup in duplicates:
self._map.pop(dup)

def __contains__(self, key: "(T, T)") -> "bool":
return key in self._map
Expand Down