Пример #1
0
        private static int[] SuffixSort(byte[] oldData)
        {
            int[] array = new int[256];
            for (int i = 0; i < oldData.Length; i++)
            {
                byte b = oldData[i];
                array[(int)b]++;
            }
            for (int j = 1; j < 256; j++)
            {
                array[j] += array[j - 1];
            }
            for (int k = 255; k > 0; k--)
            {
                array[k] = array[k - 1];
            }
            array[0] = 0;
            int[] array2 = new int[oldData.Length + 1];
            for (int l = 0; l < oldData.Length; l++)
            {
                array2[++array[(int)oldData[l]]] = l;
            }
            int[] array3 = new int[oldData.Length + 1];
            for (int m = 0; m < oldData.Length; m++)
            {
                array3[m] = array[(int)oldData[m]];
            }
            for (int n = 1; n < 256; n++)
            {
                if (array[n] == array[n - 1] + 1)
                {
                    array2[array[n]] = -1;
                }
            }
            array2[0] = -1;
            int num = 1;

            while (array2[0] != -(oldData.Length + 1))
            {
                int num2 = 0;
                int num3 = 0;
                while (num3 < oldData.Length + 1)
                {
                    if (array2[num3] < 0)
                    {
                        num2 -= array2[num3];
                        num3 -= array2[num3];
                    }
                    else
                    {
                        if (num2 != 0)
                        {
                            array2[num3 - num2] = -num2;
                        }
                        num2 = array3[array2[num3]] + 1 - num3;
                        BinaryPatchUtility.Split(array2, array3, num3, num2, num);
                        num3 += num2;
                        num2  = 0;
                    }
                }
                if (num2 != 0)
                {
                    array2[num3 - num2] = -num2;
                }
                num += num;
            }
            for (int num4 = 0; num4 < oldData.Length + 1; num4++)
            {
                array2[array3[num4]] = num4;
            }
            return(array2);
        }
Пример #2
0
 private static void Split(int[] I, int[] v, int start, int len, int h)
 {
     if (len < 16)
     {
         int num;
         for (int i = start; i < start + len; i += num)
         {
             num = 1;
             int num2 = v[I[i] + h];
             int num3 = 1;
             while (i + num3 < start + len)
             {
                 if (v[I[i + num3] + h] < num2)
                 {
                     num2 = v[I[i + num3] + h];
                     num  = 0;
                 }
                 if (v[I[i + num3] + h] == num2)
                 {
                     BinaryPatchUtility.Swap(ref I[i + num], ref I[i + num3]);
                     num++;
                 }
                 num3++;
             }
             for (int j = 0; j < num; j++)
             {
                 v[I[i + j]] = i + num - 1;
             }
             if (num == 1)
             {
                 I[i] = -1;
             }
         }
     }
     else
     {
         int num4 = v[I[start + len / 2] + h];
         int num5 = 0;
         int num6 = 0;
         for (int k = start; k < start + len; k++)
         {
             if (v[I[k] + h] < num4)
             {
                 num5++;
             }
             if (v[I[k] + h] == num4)
             {
                 num6++;
             }
         }
         num5 += start;
         num6 += num5;
         int l    = start;
         int num7 = 0;
         int num8 = 0;
         while (l < num5)
         {
             if (v[I[l] + h] < num4)
             {
                 l++;
             }
             else if (v[I[l] + h] == num4)
             {
                 BinaryPatchUtility.Swap(ref I[l], ref I[num5 + num7]);
                 num7++;
             }
             else
             {
                 BinaryPatchUtility.Swap(ref I[l], ref I[num6 + num8]);
                 num8++;
             }
         }
         while (num5 + num7 < num6)
         {
             if (v[I[num5 + num7] + h] == num4)
             {
                 num7++;
             }
             else
             {
                 BinaryPatchUtility.Swap(ref I[num5 + num7], ref I[num6 + num8]);
                 num8++;
             }
         }
         if (num5 > start)
         {
             BinaryPatchUtility.Split(I, v, start, num5 - start, h);
         }
         for (l = 0; l < num6 - num5; l++)
         {
             v[I[num5 + l]] = num6 - 1;
         }
         if (num5 == num6 - 1)
         {
             I[num5] = -1;
         }
         if (start + len > num6)
         {
             BinaryPatchUtility.Split(I, v, num6, start + len - num6, h);
         }
     }
 }