Add a connector between wire1 and wire2 in the network.
(self, wire1, wire2)
| 41 | self.addConnector(wire1, wire2) |
| 42 | |
| 43 | def addConnector(self, wire1, wire2): |
| 44 | """Add a connector between wire1 and wire2 in the network.""" |
| 45 | if wire1 == wire2: |
| 46 | return |
| 47 | |
| 48 | if wire1 > wire2: |
| 49 | wire1, wire2 = wire2, wire1 |
| 50 | |
| 51 | try: |
| 52 | last_level = self[-1] |
| 53 | except IndexError: |
| 54 | # Empty network, create new level and connector |
| 55 | self.append({wire1: wire2}) |
| 56 | return |
| 57 | |
| 58 | for wires in last_level.items(): |
| 59 | if wires[1] >= wire1 and wires[0] <= wire2: |
| 60 | self.append({wire1: wire2}) |
| 61 | return |
| 62 | |
| 63 | last_level[wire1] = wire2 |
| 64 | |
| 65 | def sort(self, values): |
| 66 | """Sort the values in-place based on the connectors in the network.""" |