public void JoinWith(Circuit c, IList<GateConnection> joins) { // add all of the gates in the other circuit. we need to make sure that there are there is no overlap Debug.Assert(!Gates.Intersect(c.Gates).Any()); Gates.UnionWith(c.Gates); InputAddrs.UnionWith(c.InputAddrs); OutputAddrs.UnionWith(c.OutputAddrs); foreach (var inAddr in c.InputConnectionCounterparties.Keys) { var outAddr = c.InputConnectionCounterparties[inAddr]; InputConnectionCounterparties[inAddr] = outAddr; OutputConnectionCounterparties[outAddr] = inAddr; } foreach (var join in joins) { AddConnection(join); } TopologicalOrderImpl = null; }
public PermutationNetwork(int wireCount) { WireCount = wireCount; LastGateForWire = new OutputGateAddress[wireCount]; FirstGateForWire = new InputGateAddress[wireCount]; Circuit = new Circuit(); WireGateList = new List<Gate>[wireCount]; for (int i = 0; i < wireCount; i++) WireGateList[i] = new List<Gate>(); }
public object Clone(out Dictionary<Gate, Gate> mapping) { var clone = new Circuit(); mapping = new Dictionary<Gate, Gate>(); // add all of the gates and connections that I have foreach (var gate in Gates) { var gateClone = gate.Copy() as Gate; clone.Gates.Add(gateClone); mapping.Add(gate, gateClone); } foreach (var input in InputAddrs) { clone.InputAddrs.Add(new InputGateAddress(mapping[input.Gate], input.Port)); } foreach (var output in OutputAddrs) { clone.OutputAddrs.Add(new OutputGateAddress(mapping[output.Gate], output.Port)); } foreach (var oldInputGate in InputConnectionCounterparties.Keys) { var newInputGate = new InputGateAddress(mapping[oldInputGate.Gate], oldInputGate.Port); var oldOutputGate = InputConnectionCounterparties[oldInputGate]; var newOutputGate = new OutputGateAddress(mapping[oldOutputGate.Gate], oldOutputGate.Port); clone.InputConnectionCounterparties[newInputGate] = newOutputGate; clone.OutputConnectionCounterparties[newOutputGate] = newInputGate; } return clone; }