MpcLib.Circuits.PermutationNetwork.AppendGate C# (CSharp) Method

AppendGate() public method

public AppendGate ( Gate gate, int wires ) : void
gate Gate
wires int
return void
        public void AppendGate(Gate gate, int[] wires)
        {
            Debug.Assert(gate.InputCount == gate.OutputCount);
            Debug.Assert(gate.InputCount == wires.Length);

            ISet<GateConnection> joins = new HashSet<GateConnection>();

            for (int i = 0; i < wires.Length; i++)
            {
                int wire = wires[i];
                if (LastGateForWire[wire] != null)
                    joins.Add(new GateConnection(LastGateForWire[wire], gate.GetLocalInputAddress(i)));

                LastGateForWire[wire] = gate.GetLocalOutputAddress(i);
                if (FirstGateForWire[wire] == null)
                    FirstGateForWire[wire] = gate.GetLocalInputAddress(i);

                WireGateList[wire].Add(gate);
            }

            Circuit.AddGate(gate, joins);
        }

Usage Example

示例#1
0
        private PermutationNetwork CreateBorderSorter(int borderBitLength, int intraBlockSortQuality)
        {
            PermutationNetwork pn = new PermutationNetwork(1 << (borderBitLength + 1));

            int borderSize = 1 << borderBitLength;
            int listCount  = (1 << (intraBlockSortQuality + 1));
            int listSize   = borderSize / listCount;

            pn.AppendGate(PermutationGateFactory.CreateUnshuffleGate(borderSize, listCount), 0);
            pn.AppendGate(PermutationGateFactory.CreateUnshuffleGate(borderSize, listCount), borderSize);

            // merge the corresponding lists
            for (int i = 0; i < listCount; i++)
            {
                int[] wires = new int[listSize * 2];
                for (int j = 0; i < listSize; i++)
                {
                    wires[j]            = i * listSize + j;
                    wires[j + listSize] = wires[j] + borderSize;
                }

                pn.AppendNetwork(SortingNetworkFactory.CreateBitonicMerge(listSize * 2, false), wires);
            }

            // shuffle the lists back into the blocks
            pn.AppendGate(PermutationGateFactory.CreateShuffleGate(borderSize, listCount), 0);
            pn.AppendGate(PermutationGateFactory.CreateShuffleGate(borderSize, listCount), borderSize);

            return(pn);
        }
All Usage Examples Of MpcLib.Circuits.PermutationNetwork::AppendGate