Browse Source

make nodes and lines hashable again

devel
Stefan Holst 4 years ago
parent
commit
c3e4090f31
  1. 10
      src/kyupy/circuit.py

10
src/kyupy/circuit.py

@ -100,10 +100,15 @@ class Node: @@ -100,10 +100,15 @@ class Node:
self.circuit = None
def __eq__(self, other):
"""Checks equality of node name and kind. Does not check pin connections.
"""Checks equality of node name and kind. Does not check pin connections.
This is ok, because (name, kind) is unique within a circuit.
"""
return self.name == other.name and self.kind == other.kind
def __hash__(self):
return hash((self.name, self.kind))
class Line:
"""A line is a directional 1:1 connection between two nodes.
@ -181,6 +186,9 @@ class Line: @@ -181,6 +186,9 @@ class Line:
return self.driver == other.driver and self.driver_pin == other.driver_pin and \
self.reader == other.reader and self.reader_pin == other.reader_pin
def __hash__(self):
return hash((self.driver, self.driver_pin, self.reader, self.reader_pin))
class Circuit:
"""A Circuit is a container for interconnected nodes and lines.

Loading…
Cancel
Save