From c3e4090f31b35d278ad5bcf2b1ee644191137a15 Mon Sep 17 00:00:00 2001 From: Stefan Holst Date: Sun, 28 Mar 2021 19:44:19 +0900 Subject: [PATCH] make nodes and lines hashable again --- src/kyupy/circuit.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/kyupy/circuit.py b/src/kyupy/circuit.py index d8c3182..53b2e51 100644 --- a/src/kyupy/circuit.py +++ b/src/kyupy/circuit.py @@ -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: 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.