Esempio n. 1
0
        /// <summary>
        /// 数组排序
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <param name="values">待排序数组</param>
        /// <param name="getKey">排序键值获取器</param>
        /// <param name="startIndex">起始位置</param>
        /// <param name="count">排序数据数量</param>
        /// <param name="fixedIndex">索引位置</param>
        /// <returns>排序后的数组</returns>
        private unsafe static valueType[] getSort/*Compare[0]*//*Compare[0]*/ <valueType>
            (valueType[] values, func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, int startIndex, int count
            , /*Type[1]*/ ulongSortIndex /*Type[1]*/ *fixedIndex)
        {
            /*Type[1]*/
            ulongSortIndex /*Type[1]*/ *writeIndex = fixedIndex;

            if (count > 1)
            {
                if (getKey == null)
                {
                    log.Default.Throw(log.exceptionType.Null);
                }
                for (int index = startIndex, endIndex = startIndex + count; index != endIndex; ++index)
                {
                    *writeIndex++ = new /*Type[1]*/ ulongSortIndex /*Type[1]*/ {
                        Value = getKey(values[index]), Index = index
                    };
                }
                sort/*Compare[0]*//*Compare[0]*/ (writeIndex = fixedIndex, fixedIndex + count - 1);
            }
            else
            {
                *fixedIndex = new /*Type[1]*/ ulongSortIndex /*Type[1]*/ {
                    Index = startIndex
                }
            };
            valueType[] newValues = new valueType[count];
            for (int index = 0; index != newValues.Length; ++index)
            {
                newValues[index] = values[(*writeIndex++).Index];
            }
            return(newValues);
        }
    }
Esempio n. 2
0
        /// <summary>
        /// 数组范围排序
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <param name="values">待排序数组</param>
        /// <param name="startIndex">起始位置</param>
        /// <param name="count">排序范围数据数量</param>
        /// <param name="getKey">排序键值获取器</param>
        /// <param name="skipCount">跳过数据数量</param>
        /// <param name="getCount">排序数据数量</param>
        /// <param name="fixedIndex">索引位置</param>
        /// <returns>排序后的数组</returns>
        private unsafe static valueType[] getRangeSort/*Compare[0]*//*Compare[0]*/ <valueType>
            (valueType[] values, int startIndex, int count, func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, int skipCount, int getCount
            , /*Type[2]*/ ulongSortIndex /*Type[2]*/ *fixedIndex)
        {
            /*Type[2]*/
            ulongSortIndex /*Type[2]*/ *writeIndex = fixedIndex;

            for (int index = startIndex, endIndex = startIndex + count; index != endIndex; ++index)
            {
                *writeIndex++ = new /*Type[2]*/ ulongSortIndex /*Type[2]*/ {
                    Value = getKey(values[index]), Index = index
                };
            }
            new /*Type[3]*/ ulongRangeIndexSorter/*Type[3]*//*Compare[0]*//*Compare[0]*/
            {
                SkipCount   = fixedIndex + skipCount,
                GetEndIndex = fixedIndex + skipCount + getCount - 1
            }.Sort(fixedIndex, fixedIndex + count - 1);
            valueType[] newValues = new valueType[getCount];
            writeIndex = fixedIndex + skipCount;
            for (int index = 0; index != newValues.Length; ++index)
            {
                newValues[index] = values[(*writeIndex++).Index];
            }
            return(newValues);
        }
Esempio n. 3
0
            /// <summary>
            /// 根据数组获取排序索引
            /// </summary>
            /// <typeparam name="valueType">数组类型</typeparam>
            /// <param name="values">数组</param>
            /// <param name="getValue">数据排序值获取器</param>
            /// <returns>排序索引</returns>
            public unsafe static /*Type[1]*/     ulongSortIndex /*Type[1]*/[] Get <valueType>(valueType[] values, func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getValue)
            {
                if (values.length() != 0)
                {
                    if (getValue == null)
                    {
                        log.Default.Throw(log.exceptionType.Null);
                    }
                    /*Type[1]*/
                    ulongSortIndex /*Type[1]*/[] indexs = new /*Type[1]*/ ulongSortIndex /*Type[1]*/[values.Length];
                    fixed(/*Type[1]*/ ulongSortIndex /*Type[1]*/ *indexFixed = indexs)
                    {
                        /*Type[1]*/
                        ulongSortIndex /*Type[1]*/ *write = indexFixed;

                        for (int index = 0; index != values.Length; ++index)
                        {
                            (*write).Value = getValue(values[index]);
                            (*write).Index = index;
                            ++write;
                        }
                    }

                    return(indexs);
                }
                return(nullValue </*Type[1]*/ ulongSortIndex /*Type[1]*/> .Array);
            }
Esempio n. 4
0
 /// <summary>
 /// 数组范围排序
 /// </summary>
 /// <typeparam name="valueType">数据类型</typeparam>
 /// <param name="values">待排序数组</param>
 /// <param name="startIndex">起始位置</param>
 /// <param name="count">排序范围数据数量</param>
 /// <param name="getKey">排序键值获取器</param>
 /// <param name="skipCount">跳过数据数量</param>
 /// <param name="getCount">排序数据数量</param>
 /// <returns>排序后的数组</returns>
 public unsafe static valueType[] GetRangeSort/*Compare[0]*//*Compare[0]*/ <valueType>
     (valueType[] values, int startIndex, int count, func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, int skipCount, int getCount)
 {
     array.range range = new array.range(values.length(), startIndex, count);
     if ((count = range.GetCount) != 0)
     {
         array.range getRange = new array.range(count, skipCount, getCount);
         if ((getCount = getRange.GetCount) != 0)
         {
             if (getKey == null)
             {
                 log.Default.Throw(log.exceptionType.Null);
             }
             if (values.Length > (config.pub.Default.StreamBufferLength >> 4))
             {
                 /*Type[2]*/
                 ulongSortIndex /*Type[2]*/[] indexs = new /*Type[2]*/ ulongSortIndex /*Type[2]*/[count];
                 fixed(/*Type[2]*/ ulongSortIndex /*Type[2]*/ *fixedIndex = indexs)
                 {
                     return(getRangeSort/*Compare[0]*//*Compare[0]*/
                                (values, range.SkipCount, count, getKey, getRange.SkipCount, getCount, fixedIndex));
                 }
             }
             else
             {
                 /*Type[2]*/
                 ulongSortIndex /*Type[2]*/ *fixedIndex = stackalloc /*Type[2]*/ ulongSortIndex /*Type[2]*/[count];
                 return(getRangeSort/*Compare[0]*//*Compare[0]*/
                            (values, range.SkipCount, count, getKey, getRange.SkipCount, getCount, fixedIndex));
             }
         }
     }
     return(nullValue <valueType> .Array);
 }
Esempio n. 5
0
 /// <summary>
 /// 根据数组获取排序索引
 /// </summary>
 /// <typeparam name="valueType">数组类型</typeparam>
 /// <param name="indexFixed">排序索引数组</param>
 /// <param name="values">数组</param>
 /// <param name="getValue">数据排序值获取器</param>
 /// <param name="startIndex">起始位置</param>
 /// <param name="count">排序数据数量</param>
 internal unsafe static void Create <valueType>(/*Type[1]*/ ulongSortIndex /*Type[1]*/ *indexFixed, valueType[] values, Func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getValue, int startIndex, int count)
 {
     for (int endIndex = startIndex + count; startIndex != endIndex; (*indexFixed++).Set(getValue(values[startIndex]), startIndex++))
     {
         ;
     }
 }
Esempio n. 6
0
        /// <summary>
        /// 排序去除Top N
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <param name="values">待排序数组</param>
        /// <param name="getKey">排序键值获取器</param>
        /// <param name="count">排序数据数量</param>
        /// <returns>排序后的数据</returns>
        private unsafe static valueType[] getRemoveTop/*Compare[0]*//*Compare[0]*/ <valueType>
            (valueType[] values, func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, int count)
        {
            valueType[] newValues = new valueType[count];
            count = values.Length - count;
            uint sqrtMod;
            int  length = Math.Min(Math.Max(count << 2, count + (int)number.sqrt((uint)values.Length, out sqrtMod)), values.Length);

            if (length > (config.pub.Default.StreamBufferLength >> 4))
            {
                /*Type[2]*/
                ulongSortIndex /*Type[2]*/[] removeValues = new /*Type[2]*/ ulongSortIndex /*Type[2]*/[length];
                fixed(/*Type[2]*/ ulongSortIndex /*Type[2]*/ *removeFixed = removeValues)
                {
                    removeTop/*Compare[0]*//*Compare[0]*/ (values, getKey, count, newValues, length, removeFixed);
                }
            }
            else
            {
                /*Type[2]*/
                ulongSortIndex /*Type[2]*/ *removeFixed = stackalloc /*Type[2]*/ ulongSortIndex /*Type[2]*/[length];
                removeTop/*Compare[0]*//*Compare[0]*/ (values, getKey, count, newValues, length, removeFixed);
            }
            return(newValues);
        }
Esempio n. 7
0
        /// <summary>
        /// 排序取Top N
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <param name="values">待排序数组</param>
        /// <param name="getKey">排序键值获取器</param>
        /// <param name="count">排序数据数量</param>
        /// <param name="length">排序缓存区尺寸</param>
        /// <param name="indexFixed">索引位置</param>
        /// <returns>排序后的数据</returns>
        private unsafe static valueType[] getTop/*Compare[0]*//*Compare[0]*/ <valueType>
            (valueType[] values, func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, int count, int length
            , /*Type[2]*/ ulongSortIndex /*Type[2]*/ *indexFixed)
        {
            /*Type[2]*/
            ulongSortIndex /*Type[2]*/ *writeEnd = indexFixed;
            int index = 0;

            while (index != length)
            {
                *writeEnd++ = new /*Type[2]*/ ulongSortIndex /*Type[2]*/ {
                    Value = getKey(values[index]), Index = index
                };
                ++index;
            }
            /*Type[2]*/
            ulongSortIndex /*Type[2]*/ *writeStat = indexFixed + count, writeIndex = writeStat;
            /*Type[3]*/
            ulongRangeIndexSorter /*Type[3]*//*Compare[0]*//*Compare[0]*/ sort
                = new /*Type[3]*/ ulongRangeIndexSorter/*Type[3]*//*Compare[0]*//*Compare[0]*/
                {
                SkipCount   = writeStat - 1,
                GetEndIndex = writeStat - 1
                };

            sort.Sort(indexFixed, --writeEnd);
            for (/*Type[0]*/ ulong /*Type[0]*/ maxValue = (*sort.SkipCount).Value; index != values.Length; ++index)
            {
                /*Type[0]*/
                ulong /*Type[0]*/ value = getKey(values[index]);
                if (value /*Compare[1]*/ < /*Compare[1]*/ maxValue)
                {
                    *writeIndex = new /*Type[2]*/ ulongSortIndex /*Type[2]*/ {
                        Value = value, Index = index
                    };
                    if (writeIndex == writeEnd)
                    {
                        sort.Sort(indexFixed, writeEnd);
                        writeIndex = writeStat;
                        maxValue   = (*sort.SkipCount).Value;
                    }
                    else
                    {
                        ++writeIndex;
                    }
                }
            }
            if (writeIndex != writeStat)
            {
                sort.Sort(indexFixed, --writeIndex);
            }
            valueType[] newValues = new valueType[count];
            for (writeIndex = indexFixed, index = 0; index != count; ++index)
            {
                newValues[index] = values[(*writeIndex++).Index];
            }
            return(newValues);
        }
Esempio n. 8
0
        /// <summary>
        /// 排序去除Top N
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <param name="values">待排序数组</param>
        /// <param name="getKey">排序键值获取器</param>
        /// <param name="count">排序数据数量</param>
        /// <param name="newValues">目标数据数组</param>
        /// <param name="length">排序缓存区尺寸</param>
        /// <param name="removeFixed">索引位置</param>
        private unsafe static void removeTop/*Compare[0]*//*Compare[0]*/ <valueType>
            (valueType[] values, Func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, int count, valueType[] newValues, int length
            , /*Type[2]*/ ulongSortIndex /*Type[2]*/ *removeFixed)
        {
            int index = 0, writeIndex = 0;
            /*Type[2]*/
            ulongSortIndex /*Type[2]*/ *removeEnd = removeFixed;

            while (index != length)
            {
                (*removeEnd++).Set(getKey(values[index]), index++);
            }
            /*Type[2]*/
            ulongSortIndex /*Type[2]*/ *removeStart = removeFixed + (count = length - count), removeIndex = removeFixed;
            /*Type[3]*/
            ulongRangeIndexSorter /*Type[3]*//*Compare[0]*//*Compare[0]*/ sort
                = new /*Type[3]*/ ulongRangeIndexSorter/*Type[3]*//*Compare[0]*//*Compare[0]*/
                {
                SkipCount   = removeStart,
                GetEndIndex = removeStart
                };

            sort.Sort(removeFixed, --removeEnd);
            while (writeIndex != count)
            {
                newValues[writeIndex++] = values[(*removeIndex++).Index];
            }
            for (/*Type[0]*/ ulong /*Type[0]*/ maxValue = (*removeStart).Value; index != values.Length; ++index)
            {
                /*Type[0]*/
                ulong /*Type[0]*/ value = getKey(values[index]);
                if (value /*Compare[2]*/ <= /*Compare[2]*/ maxValue)
                {
                    newValues[writeIndex++] = values[index];
                }
                else
                {
                    (*--removeIndex).Set(value, index);
                    if (removeIndex == removeFixed)
                    {
                        sort.Sort(removeFixed, removeEnd);
                        for (removeIndex = removeFixed; removeIndex != removeStart; newValues[writeIndex++] = values[(*removeIndex++).Index])
                        {
                            ;
                        }
                        maxValue = (*removeStart).Value;
                    }
                }
            }
            if (removeIndex != removeStart)
            {
                sort.Sort(removeIndex, removeEnd);
                while (removeIndex != removeStart)
                {
                    newValues[writeIndex++] = values[(*removeIndex++).Index];
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 根据数组获取排序索引
        /// </summary>
        /// <typeparam name="valueType">数组类型</typeparam>
        /// <param name="indexFixed">排序索引数组</param>
        /// <param name="values">数组</param>
        /// <param name="getValue">数据排序值获取器</param>
        internal unsafe static void Create <valueType>(/*Type[1]*/ ulongSortIndex /*Type[1]*/ *indexFixed, valueType[] values, Func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getValue)
        {
            int index = 0;

            foreach (valueType value in values)
            {
                (*indexFixed++).Set(getValue(value), index++);
            }
        }
Esempio n. 10
0
 /// <summary>
 /// 数组排序
 /// </summary>
 /// <typeparam name="valueType">数据类型</typeparam>
 /// <param name="values">待排序数组</param>
 /// <param name="getKey">排序键值获取器</param>
 /// <param name="startIndex">起始位置</param>
 /// <param name="count">排序数据数量</param>
 /// <param name="fixedIndex">索引位置</param>
 /// <returns>排序后的数组</returns>
 private unsafe static valueType[] getSort/*Compare[0]*//*Compare[0]*/ <valueType>
     (valueType[] values, Func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, int startIndex, int count
     , /*Type[1]*/ ulongSortIndex /*Type[1]*/ *fixedIndex)
 {
     /*Type[1]*/
     ulongSortIndex /*Type[1]*/.Create(fixedIndex, values, getKey, startIndex, count);
     sort/*Compare[0]*//*Compare[0]*/ (fixedIndex, fixedIndex + count - 1);
     return /*Type[1]*/ (ulongSortIndex /*Type[1]*/.Create(fixedIndex, values, count));
 }
Esempio n. 11
0
        /// <summary>
        /// 数组范围排序
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <param name="values">待排序数组</param>
        /// <param name="getKey">排序键值获取器</param>
        /// <param name="skipCount">跳过数据数量</param>
        /// <param name="getCount">排序数据数量</param>
        /// <param name="fixedIndex">索引位置</param>
        /// <returns>排序后的数组</returns>
        private unsafe static valueType[] getRangeSort/*Compare[0]*//*Compare[0]*/ <valueType>
            (valueType[] values, Func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, int skipCount, int getCount
            , /*Type[2]*/ ulongSortIndex /*Type[2]*/ *fixedIndex)
        {
            /*Type[2]*/
            ulongSortIndex /*Type[2]*/ *writeIndex = fixedIndex;

            for (int index = 0; index != values.Length; (*writeIndex++).Set(getKey(values[index]), index++))
            {
                ;
            }
            return(getRangeSort/*Compare[0]*//*Compare[0]*/ (values, skipCount, getCount, fixedIndex));
        }
Esempio n. 12
0
        /// <summary>
        /// 数组范围排序
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <param name="values">待排序数组</param>
        /// <param name="skipCount">跳过数据数量</param>
        /// <param name="getCount">排序数据数量</param>
        /// <param name="fixedIndex">索引位置</param>
        /// <returns>排序后的数组</returns>
        private unsafe static valueType[] getRangeSort/*Compare[0]*//*Compare[0]*/ <valueType>
            (valueType[] values, int skipCount, int getCount, /*Type[2]*/ ulongSortIndex /*Type[2]*/ *fixedIndex)
        {
            new /*Type[3]*/ ulongRangeIndexSorter/*Type[3]*//*Compare[0]*//*Compare[0]*/
            {
                SkipCount   = fixedIndex + skipCount,
                GetEndIndex = fixedIndex + skipCount + getCount - 1
            }.Sort(fixedIndex, fixedIndex + values.Length - 1);
            valueType[] newValues = new valueType[getCount];
            /*Type[2]*/
            ulongSortIndex /*Type[2]*/ *writeIndex = fixedIndex + skipCount;

            for (int index = 0; index != newValues.Length; ++index)
            {
                newValues[index] = values[(*writeIndex++).Index];
            }
            return(newValues);
        }
Esempio n. 13
0
        /// <summary>
        /// 排序取Top N
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <param name="values">待排序数组</param>
        /// <param name="getKey">排序键值获取器</param>
        /// <param name="count">排序数据数量</param>
        /// <returns>排序后的数据</returns>
        private unsafe static valueType[] getTop/*Compare[0]*//*Compare[0]*/ <valueType>
            (valueType[] values, func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, int count)
        {
            uint sqrtMod;
            int  length = Math.Min(Math.Max(count << 2, count + (int)number.sqrt((uint)values.Length, out sqrtMod)), values.Length);

            if (length > (config.pub.Default.StreamBufferLength >> 4))
            {
                /*Type[2]*/
                ulongSortIndex /*Type[2]*/[] indexs = new /*Type[2]*/ ulongSortIndex /*Type[2]*/[length];
                fixed(/*Type[2]*/ ulongSortIndex /*Type[2]*/ *indexFixed = indexs)
                {
                    return(getTop/*Compare[0]*//*Compare[0]*/ (values, getKey, count, length, indexFixed));
                }
            }
            else
            {
                /*Type[2]*/
                ulongSortIndex /*Type[2]*/ *indexFixed = stackalloc /*Type[2]*/ ulongSortIndex /*Type[2]*/[length];
                return(getTop/*Compare[0]*//*Compare[0]*/ (values, getKey, count, length, indexFixed));
            }
        }
Esempio n. 14
0
 /// <summary>
 /// 数组排序
 /// </summary>
 /// <typeparam name="valueType">数据类型</typeparam>
 /// <param name="values">待排序数组</param>
 /// <param name="getKey">排序键值获取器</param>
 /// <returns>排序后的数组</returns>
 public unsafe static valueType[] GetSort/*Compare[0]*//*Compare[0]*/ <valueType>
     (valueType[] values, func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey)
 {
     if (values.length() != 0)
     {
         if (values.Length > (config.pub.Default.StreamBufferLength >> 4))
         {
             /*Type[1]*/
             ulongSortIndex /*Type[1]*/[] indexs = new /*Type[1]*/ ulongSortIndex /*Type[1]*/[values.Length];
             fixed(/*Type[1]*/ ulongSortIndex /*Type[1]*/ *fixedIndex = indexs)
             {
                 return(getSort/*Compare[0]*//*Compare[0]*/ (values, getKey, fixedIndex));
             }
         }
         else
         {
             /*Type[1]*/
             ulongSortIndex /*Type[1]*/ *fixedIndex = stackalloc /*Type[1]*/ ulongSortIndex /*Type[1]*/[values.Length];
             return(getSort/*Compare[0]*//*Compare[0]*/ (values, getKey, fixedIndex));
         }
     }
     return(nullValue <valueType> .Array);
 }
Esempio n. 15
0
 /// <summary>
 /// 数组排序
 /// </summary>
 /// <typeparam name="valueType">数据类型</typeparam>
 /// <param name="values">待排序数组</param>
 /// <param name="getKey">排序键值获取器</param>
 /// <param name="startIndex">起始位置</param>
 /// <param name="count">排序数据数量</param>
 /// <returns>排序后的数组</returns>
 public unsafe static valueType[] GetSort/*Compare[0]*//*Compare[0]*/ <valueType>
     (valueType[] values, func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, int startIndex, int count)
 {
     array.range range = new array.range(values.length(), startIndex, count);
     if ((count = range.GetCount) != 0)
     {
         if (count > (config.pub.Default.StreamBufferLength >> 4))
         {
             /*Type[1]*/
             ulongSortIndex /*Type[1]*/[] indexs = new /*Type[1]*/ ulongSortIndex /*Type[1]*/[count];
             fixed(/*Type[1]*/ ulongSortIndex /*Type[1]*/ *fixedIndex = indexs)
             {
                 return(getSort/*Compare[0]*//*Compare[0]*/ (values, getKey, range.SkipCount, count, fixedIndex));
             }
         }
         else
         {
             /*Type[1]*/
             ulongSortIndex /*Type[1]*/ *fixedIndex = stackalloc /*Type[1]*/ ulongSortIndex /*Type[1]*/[count];
             return(getSort/*Compare[0]*//*Compare[0]*/ (values, getKey, range.SkipCount, count, fixedIndex));
         }
     }
     return(nullValue <valueType> .Array);
 }
Esempio n. 16
0
 /// <summary>
 /// 数组排序
 /// </summary>
 /// <typeparam name="valueType">数据类型</typeparam>
 /// <param name="values">待排序数组</param>
 /// <param name="getKey">排序键值获取器</param>
 /// <param name="fixedIndex">索引位置</param>
 /// <returns>排序后的数组</returns>
 private unsafe static valueType[] getSort/*Compare[0]*//*Compare[0]*/ <valueType>
     (valueType[] values, Func <valueType, /*Type[0]*/ ulong /*Type[0]*/> getKey, /*Type[1]*/ ulongSortIndex /*Type[1]*/ *fixedIndex)
 {
     /*Type[1]*/ ulongSortIndex /*Type[1]*/.Create(fixedIndex, values, getKey);
     sort/*Compare[0]*//*Compare[0]*/ (fixedIndex, fixedIndex + values.Length - 1);
     return /*Type[1]*/ (ulongSortIndex /*Type[1]*/.Create(fixedIndex, values, values.Length));
 }
Esempio n. 17
0
 /// <summary>
 /// 根据排序索引获取数组
 /// </summary>
 /// <typeparam name="valueType">数组类型</typeparam>
 /// <param name="indexFixed">排序索引数组</param>
 /// <param name="values">数组</param>
 /// <param name="count">排序数据数量</param>
 /// <returns>排序后的数组</returns>
 internal unsafe static               valueType[] Create <valueType>(/*Type[1]*/ ulongSortIndex /*Type[1]*/ *indexFixed, valueType[] values, int count)
 {
     valueType[] newValues = new valueType[count];
     for (int index = 0; index != count; ++index)
     {
         newValues[index] = values[(*indexFixed++).Index];
     }
     return(newValues);
 }
Esempio n. 18
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);
 }
Esempio n. 19
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);
 }