CreateBitonicMerge() public static méthode

public static CreateBitonicMerge ( int wireCount, bool invertOrder ) : PermutationNetwork
wireCount int
invertOrder bool
Résultat PermutationNetwork
Exemple #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);
        }
Exemple #2
0
        // Lemma 4.3
        private PermutationNetwork CreateFinalSorter(int blockBitLength)
        {
            PermutationNetwork pn = new PermutationNetwork(1 << K);

            int blockSize  = 1 << blockBitLength;
            int blockCount = 1 << (K - blockBitLength);

            // sort each block, alternate orders for bitonic merge coming up
            var bitonicSort = SortingNetworkFactory.CreateBitonicSort(blockSize, false);

            for (int i = 0; i < blockCount; i++)
            {
                pn.AppendNetwork(bitonicSort, i * blockSize);
                if (i % 2 == 1)
                {
                    pn.AppendGate(PermutationGateFactory.CreateInvertGate(blockSize), i * blockSize);
                }
            }

            PermutationNetwork twoBlockMerge = SortingNetworkFactory.CreateBitonicMerge(blockSize * 2, false);

            // merge each block with the one next to it.  alternate ordern for bitonic merge coming up

            var bitonicMerge = SortingNetworkFactory.CreateBitonicMerge(blockSize * 2, false);

            for (int i = 0; i < blockCount; i += 2)
            {
                pn.AppendNetwork(bitonicMerge.Clone() as PermutationNetwork, i * blockSize);
                if ((i / 2) % 2 == 1)
                {
                    pn.AppendGate(PermutationGateFactory.CreateInvertGate(2 * blockSize), i * blockSize);
                }
            }

            // do another round of merges, this time offset by 1
            for (int i = 1; i < blockCount; i += 2)
            {
                pn.AppendNetwork(bitonicMerge.Clone() as PermutationNetwork, i * blockSize);
            }

            // the last block will be inverted, so uninvert it
            pn.AppendGate(PermutationGateFactory.CreateInvertGate(blockSize), (blockCount - 1) * blockSize);

            return(pn);
        }