コード例 #1
0
ファイル: Merging.cs プロジェクト: dan10097110/D-CSharp-Lib
 static void Intern(int[] a, int start, int count)
 {
     if (count > 2048)
     {
         int firstCount = count >> 1;
         Intern(a, start, firstCount);
         Intern(a, start + firstCount, count - firstCount);
         Combine2Sections(a, start, count);
     }
     else if (count > 1)
     {
         Exchanging.Comb(a, start, count);
     }
 }
コード例 #2
0
ファイル: Merging.cs プロジェクト: dan10097110/D-CSharp-Lib
 static void InternTri(int[] a, int start, int count)
 {
     if (count > 2048)
     {
         int firstCount = count / 3;
         InternTri(a, start, firstCount);
         InternTri(a, start + firstCount, firstCount);
         InternTri(a, start + (firstCount << 1), count - (firstCount << 1));
         Combine3Sections(a, start, count);
     }
     else if (count > 1)
     {
         Exchanging.Comb(a, start, count);
     }
 }
コード例 #3
0
ファイル: Merging.cs プロジェクト: dan10097110/D-CSharp-Lib
 public static int[] StartTri(int[] a)
 {
     for (int start = 0; start + 1 < a.Length; start += 2048)
     {
         Exchanging.Comb(a, start, System.Math.Min(a.Length - start, 2048));
     }
     for (int size = 2048; size < a.Length; size *= 3)
     {
         for (int u = 0; u + size < a.Length; u += size * 3)
         {
             Combine3Sections(a, u, size);
         }
     }
     return(a);
 }
コード例 #4
0
ファイル: Merging.cs プロジェクト: dan10097110/D-CSharp-Lib
 public static int[] Start(int[] a)
 {
     for (int start = 0; start + 1 < a.Length; start += 2048)
     {
         Exchanging.Comb(a, start, System.Math.Min(a.Length - start, 2048));
     }
     for (int firstCount = 1; firstCount < a.Length; firstCount <<= 1)
     {
         for (int start = 0; start + firstCount < a.Length; start += (firstCount << 1))
         {
             Combine2Sections(a, start, firstCount);
         }
     }
     return(a);
 }
コード例 #5
0
        protected internal void ExchangeData(int currentIndex, int exchangeIndex)
        {
            _exchangingEventArgs.CurrentItem   = Data[currentIndex];
            _exchangingEventArgs.ExchangedItem = Data[exchangeIndex];
            Exchanging?.Invoke(this, _exchangingEventArgs);

            var temporary = Data[currentIndex];

            Data[currentIndex]  = Data[exchangeIndex];
            Data[exchangeIndex] = temporary;

            _exchangeEventArgs.CurrentItem   = Data[currentIndex];
            _exchangeEventArgs.ExchangedItem = Data[exchangeIndex];
            Exchanged?.Invoke(this, _exchangeEventArgs);
        }
コード例 #6
0
        public static void Flash(int[] a)
        {
            int min = a[0], max = a[0];

            for (int i = 1; i < a.Length; i++)
            {
                if (a[i] < min)
                {
                    min = a[i];
                }
                else if (a[i] > max)
                {
                    max = a[i];
                }
            }
            double tmp = (a.Length - 1) / (double)(max - min);

            int[] b = new int[a.Length];
            for (int i = 0; i < a.Length; i++)
            {
                int j = (int)(tmp * (a[i] - min));
                if (b[j] == 0)
                {
                    b[j] = a[i];
                }
                else
                {
                    for (int k = 0; ;)
                    {
                        if (b[j + k] == 0)
                        {
                            b[j + k] = a[i];
                        }
                        else if (b[j - k] == 0)
                        {
                            b[j - k] = a[i];
                        }
                        k++;
                        if (j + k >= a.Length)
                        {
                            for (; j - k < 0; k++)
                            {
                                if (b[j - k] == 0)
                                {
                                    b[j - k] = a[i];
                                }
                            }
                            break;
                        }
                        else if (j - k < 0)
                        {
                            for (; j + k < 0; k++)
                            {
                                if (b[j + k] == 0)
                                {
                                    b[j + k] = a[i];
                                }
                            }
                            break;
                        }
                    }
                }
            }
            Exchanging.Cocktail(a);
        }