示例#1
0
        public LPSortingNetwork(int wireCount)
            : base(wireCount)
        {
            Debug.Assert(SortingNetwork.isPowerOfTwo((uint)wireCount));

            K = (int)Math.Log(wireCount, 2);

            CalculationCache = new LPSortingCalculationCache();

            AppendNetwork(new LPSortingNetwork(K, CalculationCache), 0);
        }
示例#2
0
        public static PermutationNetwork CreateButterflyTournamentRound(int wireCount)
        {
            Debug.Assert(SortingNetwork.isPowerOfTwo((uint)wireCount));

            PermutationNetwork pn = new PermutationNetwork(wireCount);

            // we want to join every wire to its corresponding wire on the other half using a compare and swap gate
            for (int i = 0; i < wireCount / 2; i++)
            {
                pn.AppendGate(new ComputationGate(ComputationGateType.COMPARE_AND_SWAP), new int[] { i, i + wireCount / 2 });
            }

            return(pn);
        }
示例#3
0
        public static PermutationNetwork CreateBitonicSort(int wireCount, bool invertOrder)
        {
            Debug.Assert(SortingNetwork.isPowerOfTwo((uint)wireCount));

            PermutationNetwork pn = new PermutationNetwork(wireCount);

            if (wireCount >= 4)
            {
                pn.AppendNetwork(CreateBitonicSort(wireCount / 2, false), 0);
                pn.AppendNetwork(CreateBitonicSort(wireCount / 2, true), wireCount / 2);
            }

            pn.AppendNetwork(CreateBitonicMerge(wireCount, invertOrder), 0);

            return(pn);
        }
示例#4
0
        public static PermutationNetwork CreateBitonicSplit(int wireCount, bool invertOrder)
        {
            Debug.Assert(SortingNetwork.isPowerOfTwo((uint)wireCount));

            PermutationNetwork pn = new PermutationNetwork(wireCount);

            for (int i = 0; i < wireCount / 2; i++)
            {
                pn.AppendGate(new ComputationGate(ComputationGateType.COMPARE_AND_SWAP), new int[] { i, i + wireCount / 2 });
                if (invertOrder)
                {
                    pn.AppendGate(PermutationGateFactory.CreateSwapGate(), new int[] { i, i + wireCount / 2 });
                }
            }

            return(pn);
        }
示例#5
0
        public static PermutationNetwork CreateButterflyTournament(int wireCount)
        {
            Debug.Assert(SortingNetwork.isPowerOfTwo((uint)wireCount));

            PermutationNetwork pn = new PermutationNetwork(wireCount);

            if (wireCount == 1)
            {
                return(pn);
            }

            pn.AppendNetwork(CreateButterflyTournamentRound(wireCount), 0);

            // recursively construct the butterfly
            if (wireCount > 2)
            {
                pn.AppendNetwork(CreateButterflyTournament(wireCount / 2), 0);
                pn.AppendNetwork(CreateButterflyTournament(wireCount / 2), wireCount / 2);
            }

            return(pn);
        }
示例#6
0
        public static PermutationNetwork CreateBinaryTreeInsertion(int wireCount)
        {
            // assume that the first input wire is the location of the unsorted element

            Debug.Assert(SortingNetwork.isPowerOfTwo((uint)wireCount));

            PermutationNetwork pn = new PermutationNetwork(wireCount);

            if (wireCount == 1)
            {
                return(pn);
            }

            pn.AppendGate(new ComputationGate(ComputationGateType.COMPARE_AND_SWAP), new int[] { 0, wireCount / 2 });

            if (wireCount > 2)
            {
                pn.AppendNetwork(CreateBinaryTreeInsertion(wireCount / 2), 0);
                pn.AppendNetwork(CreateBinaryTreeInsertion(wireCount / 2), wireCount / 2);
            }

            return(pn);
        }