public AppendNetwork ( |
||
pn | ||
wires | int | |
return | void |
public void AppendNetwork(PermutationNetwork pn, int[] wires)
{
// append the provided network to this one. join wires[i] to i
Debug.Assert(wires.Length == pn.WireCount);
List<GateConnection> joins = new List<GateConnection>();
for (int i = 0; i < wires.Length; i++)
{
int wire = wires[i];
if (LastGateForWire[wire] != null && pn.FirstGateForWire[i] != null)
{
joins.Add(new GateConnection(LastGateForWire[wire], pn.FirstGateForWire[i]));
}
if (pn.LastGateForWire[i] != null)
{
LastGateForWire[wire] = pn.LastGateForWire[i];
}
if (FirstGateForWire[wire] == null)
{
FirstGateForWire[wire] = pn.FirstGateForWire[i];
}
WireGateList[wire].AddRange(pn.WireGateList[i]);
}
Circuit.JoinWith(pn.Circuit, joins);
}
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); }