Esempio n. 1
0
 /// <summary>
 /// 范围排序
 /// </summary>
 /// <param name="startIndex">起始指针</param>
 /// <param name="endIndex">结束指针-1</param>
 public void Sort(/*Type[2]*/ ulongSortIndex /*Type[2]*/ *startIndex, /*Type[2]*/ ulongSortIndex /*Type[2]*/ *endIndex)
 {
     do
     {
         /*Type[2]*/
         ulongSortIndex /*Type[2]*/ leftValue = *startIndex, rightValue = *endIndex;
         int average = (int)(endIndex - startIndex) >> 1;
         if (average == 0)
         {
             if (leftValue.Value /*Compare[1]*/ > /*Compare[1]*/ rightValue.Value)
             {
                 *startIndex = rightValue;
                 *endIndex   = leftValue;
             }
             break;
         }
         /*Type[2]*/
         ulongSortIndex /*Type[2]*/ *averageIndex = startIndex + average, leftIndex = startIndex, rightIndex = endIndex;
         /*Type[2]*/
         ulongSortIndex /*Type[2]*/ indexValue = *averageIndex;
         if (leftValue.Value /*Compare[1]*/ > /*Compare[1]*/ indexValue.Value)
         {
             if (leftValue.Value /*Compare[1]*/ > /*Compare[1]*/ rightValue.Value)
             {
                 *rightIndex = leftValue;
                 if (indexValue.Value /*Compare[1]*/ > /*Compare[1]*/ rightValue.Value)
                 {
                     *leftIndex = rightValue;
                 }
                 else
                 {
                     *leftIndex    = indexValue;
                     *averageIndex = indexValue = rightValue;
                 }
             }
             else
             {
                 *leftIndex    = indexValue;
                 *averageIndex = indexValue = leftValue;
             }
         }
         else
         {
             if (indexValue.Value /*Compare[1]*/ > /*Compare[1]*/ rightValue.Value)
             {
                 *rightIndex = indexValue;
                 if (leftValue.Value /*Compare[1]*/ > /*Compare[1]*/ rightValue.Value)
                 {
                     *leftIndex    = rightValue;
                     *averageIndex = indexValue = leftValue;
                 }
                 else
                 {
                     *averageIndex = indexValue = rightValue;
                 }
             }
         }
         ++leftIndex;
         --rightIndex;
         /*Type[0]*/
         ulong /*Type[0]*/ value = indexValue.Value;
         do
         {
             while ((*leftIndex).Value /*Compare[2]*/ < /*Compare[2]*/ value)
             {
                 ++leftIndex;
             }
             while (value /*Compare[2]*/ < /*Compare[2]*/ (*rightIndex).Value)
             {
                 --rightIndex;
             }
             if (leftIndex < rightIndex)
             {
                 leftValue = *leftIndex;
                 *leftIndex  = *rightIndex;
                 *rightIndex = leftValue;
             }
             else
             {
                 if (leftIndex == rightIndex)
                 {
                     ++leftIndex;
                     --rightIndex;
                 }
                 break;
             }
         }while (++leftIndex <= --rightIndex);
         if (rightIndex - startIndex <= endIndex - leftIndex)
         {
             if (startIndex < rightIndex && rightIndex >= SkipCount)
             {
                 Sort(startIndex, rightIndex);
             }
             if (leftIndex > GetEndIndex)
             {
                 break;
             }
             startIndex = leftIndex;
         }
         else
         {
             if (leftIndex < endIndex && leftIndex <= GetEndIndex)
             {
                 Sort(leftIndex, endIndex);
             }
             if (rightIndex < SkipCount)
             {
                 break;
             }
             endIndex = rightIndex;
         }
     }while (startIndex < endIndex);
 }
Esempio n. 2
0
 /// <summary>
 /// 索引快速排序子过程
 /// </summary>
 /// <param name="startIndex">起始位置</param>
 /// <param name="endIndex">结束位置-1</param>
 private unsafe static void sort/*Compare[0]*//*Compare[0]*/
     (/*Type[1]*/ ulongSortIndex /*Type[1]*/ *startIndex, /*Type[1]*/ ulongSortIndex /*Type[1]*/ *endIndex)
 {
     do
     {
         /*Type[1]*/
         ulongSortIndex /*Type[1]*/ leftValue = *startIndex, rightValue = *endIndex;
         int average = (int)(endIndex - startIndex) >> 1;
         if (average == 0)
         {
             if (leftValue.Value /*Compare[1]*/ > /*Compare[1]*/ rightValue.Value)
             {
                 *startIndex = rightValue;
                 *endIndex   = leftValue;
             }
             break;
         }
         /*Type[1]*/
         ulongSortIndex /*Type[1]*/ *leftIndex = startIndex, rightIndex = endIndex, averageIndex = startIndex + average;
         /*Type[1]*/
         ulongSortIndex /*Type[1]*/ indexValue = *averageIndex;
         if (leftValue.Value /*Compare[1]*/ > /*Compare[1]*/ indexValue.Value)
         {
             if (leftValue.Value /*Compare[1]*/ > /*Compare[1]*/ rightValue.Value)
             {
                 *rightIndex = leftValue;
                 if (indexValue.Value /*Compare[1]*/ > /*Compare[1]*/ rightValue.Value)
                 {
                     *leftIndex = rightValue;
                 }
                 else
                 {
                     *leftIndex    = indexValue;
                     *averageIndex = indexValue = rightValue;
                 }
             }
             else
             {
                 *leftIndex    = indexValue;
                 *averageIndex = indexValue = leftValue;
             }
         }
         else
         {
             if (indexValue.Value /*Compare[1]*/ > /*Compare[1]*/ rightValue.Value)
             {
                 *rightIndex = indexValue;
                 if (leftValue.Value /*Compare[1]*/ > /*Compare[1]*/ rightValue.Value)
                 {
                     *leftIndex    = rightValue;
                     *averageIndex = indexValue = leftValue;
                 }
                 else
                 {
                     *averageIndex = indexValue = rightValue;
                 }
             }
         }
         ++leftIndex;
         --rightIndex;
         /*Type[0]*/
         ulong /*Type[0]*/ value = indexValue.Value;
         do
         {
             while ((*leftIndex).Value /*Compare[2]*/ < /*Compare[2]*/ value)
             {
                 ++leftIndex;
             }
             while (value /*Compare[2]*/ < /*Compare[2]*/ (*rightIndex).Value)
             {
                 --rightIndex;
             }
             if (leftIndex < rightIndex)
             {
                 leftValue = *leftIndex;
                 *leftIndex  = *rightIndex;
                 *rightIndex = leftValue;
             }
             else
             {
                 if (leftIndex == rightIndex)
                 {
                     ++leftIndex;
                     --rightIndex;
                 }
                 break;
             }
         }while (++leftIndex <= --rightIndex);
         if (rightIndex - startIndex <= endIndex - leftIndex)
         {
             if (startIndex < rightIndex)
             {
                 sort/*Compare[0]*//*Compare[0]*/ (startIndex, rightIndex);
             }
             startIndex = leftIndex;
         }
         else
         {
             if (leftIndex < endIndex)
             {
                 sort/*Compare[0]*//*Compare[0]*/ (leftIndex, endIndex);
             }
             endIndex = rightIndex;
         }
     }while (startIndex < endIndex);
 }