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); }
// the subsequent rounds private LPSortingNetwork(int k, int l, LPSortingCalculationCache calculationCache) : base(1 << k) { Console.WriteLine(k + " " + l); CalculationCache = calculationCache; K = k; if (l <= (int)Math.Floor(gamma * (l + 2)) + c + 5) { // if we would get worse by doing the procedure, then finish if (k <= l) { AppendNetwork(SortingNetworkFactory.CreateBitonicSort(1 << K, false), 0); } else { // Apply Lemma 4.3 AppendNetwork(CreateFinalSorter(l), 0); } } else { // Apply Lemma 4.2 PermutationNetwork tournament = CreateTournament(l + 2); // Apply Lemma 4.1 PermutationNetwork tournamentCorrecter = CreateBlockCorrectionNetwork(l + 2, (int)Math.Floor(gamma * (l + 2)) + c); for (int i = 0; i < 1 << (k - (l + 2)); i++) { AppendNetwork(tournament.Clone() as PermutationNetwork, i * (1 << (l + 2))); AppendNetwork(tournamentCorrecter.Clone() as PermutationNetwork, i * (1 << (l + 2))); } // Apply Lemma 4.4 PermutationNetwork neighborCorrecter = CreateBlockNeighborSorter(l + 2, l + 1, (int)Math.Floor(gamma * (l + 2)) + c + 2); AppendNetwork(neighborCorrecter, 0); AppendNetwork(new LPSortingNetwork(k, (int)Math.Floor(gamma * (l + 2)) + c + 5, CalculationCache), 0); } }
// the initial round private LPSortingNetwork(int k, LPSortingCalculationCache calculationCache) : base(1 << k) { CalculationCache = calculationCache; K = k; if (k <= (int)Math.Floor(gamma * (k)) + c + 2) { // network too small to be sorted by this method AppendNetwork(SortingNetworkFactory.CreateBitonicSort(1 << K, false), 0); } else { // Apply Lemma 4.2 AppendNetwork(CreateTournament(k), 0); // Apply Lemma 4.1 AppendNetwork(CreateBlockCorrectionNetwork(k, (int)Math.Floor(gamma * (k)) + c), 0); AppendNetwork(new LPSortingNetwork(K, (int)Math.Floor(gamma * (k)) + c + 2, CalculationCache), 0); } }
// the subsequent rounds private LPSortingNetwork(int k, int l, LPSortingCalculationCache calculationCache) : base(1 << k) { Console.WriteLine(k + " " + l); CalculationCache = calculationCache; K = k; if (l <= (int)Math.Floor(gamma * (l + 2)) + c + 5) { // if we would get worse by doing the procedure, then finish if (k <= l) AppendNetwork(SortingNetworkFactory.CreateBitonicSort(1 << K, false), 0); else // Apply Lemma 4.3 AppendNetwork(CreateFinalSorter(l), 0); } else { // Apply Lemma 4.2 PermutationNetwork tournament = CreateTournament(l + 2); // Apply Lemma 4.1 PermutationNetwork tournamentCorrecter = CreateBlockCorrectionNetwork(l + 2, (int)Math.Floor(gamma * (l + 2)) + c); for (int i = 0; i < 1 << (k - (l+2)); i++) { AppendNetwork(tournament.Clone() as PermutationNetwork, i * (1 << (l+2))); AppendNetwork(tournamentCorrecter.Clone() as PermutationNetwork, i * (1 << (l + 2))); } // Apply Lemma 4.4 PermutationNetwork neighborCorrecter = CreateBlockNeighborSorter(l + 2, l + 1, (int)Math.Floor(gamma * (l + 2)) + c + 2); AppendNetwork(neighborCorrecter, 0); AppendNetwork(new LPSortingNetwork(k, (int) Math.Floor(gamma * (l + 2)) + c + 5, CalculationCache), 0); } }