public ComparisonTestSettings(int size, int count, int maxValue, RadixType radix)
 {
     Size     = size;
     Count    = count;
     MaxValue = maxValue;
     Radix    = radix;
 }
 public XyTestSettings(int sizeX, int sizeY, int count, int maxValue, RadixType radix)
 {
     SizeX    = sizeX;
     SizeY    = sizeY;
     Count    = count;
     MaxValue = maxValue;
     Radix    = radix;
 }
        public void Sort <T>(T[] elements, RadixType radix) where T : IMonotonicObject
        {
            int negativeCount = 0;

            int[] monotonicValues = new int[elements.Length];
            for (int i = 0; i < elements.Length; i++)
            {
                monotonicValues[i] = elements[i].GetMonotonicCode();
                if (monotonicValues[i] < 0)
                {
                    negativeCount++;
                }
            }

            if (typeof(T).IsValueType)
            {
                IRadixSortForValueType <T> sorter;
                if (radix == RadixType.LSD)
                {
                    sorter = new ModifiedLSDRadixForValueTypes <T>();
                }
                else
                {
                    sorter = new ModifiedMsdRadixForValueTypes <T>();
                }
                sorter.Sort(elements);
            }
            else
            {
                IRadixSort <T> sorter;
                if (radix == RadixType.LSD)
                {
                    sorter = new ModifiedLSDRadix <T>();
                }
                else
                {
                    sorter = new ModifiedMsdRadix <T>();
                }
                sorter.Sort(elements, monotonicValues);
            }

            if (negativeCount > 0)
            {
                T[] negativeItems = new T[negativeCount];
                Array.Copy(elements, elements.Length - negativeCount, negativeItems, 0, negativeCount);
                Array.Copy(elements, 0, elements, negativeCount, elements.Length - negativeCount);
                Array.Copy(negativeItems, 0, elements, 0, negativeCount);
            }
        }
示例#4
0
        /// <summary>
        /// Converts the specified <see cref="DataValue" /> to a string using the given <see cref="RadixType" /> .
        /// </summary>
        /// <param name="radix">The <see cref="RadixType" /> .</param>
        /// <param name="value">The value.</param>
        /// <returns>
        /// A string of the <see cref="DataValue" /> interpreted using the given <see cref="RadixType" /> .
        /// </returns>
        public static string Convert(this RadixType radix, DataValue value)
        {
            switch (radix)
            {
            case RadixType.Binary:
                return(RadixTypeExtensions.ConvertToBinary(value));

            case RadixType.Octal:
                return(RadixTypeExtensions.ConvertToOctal(value));

            case RadixType.SignedDecimal:
                return(RadixTypeExtensions.ConvertToSignedDecimal(value));

            case RadixType.UnsignedDecimal:
                return(RadixTypeExtensions.ConvertToUnsignedDecimal(value));

            case RadixType.Hex:
                return(RadixTypeExtensions.ConvertToHex(value));

            default:
                throw new NotImplementedException("Unknown Radix Type.");
            }
        }