Exemple #1
0
        /// <summary>
        /// 随机排序
        /// </summary>
        /// <typeparam name="valueType">值类型</typeparam>
        /// <param name="values">排序数组</param>
        /// <param name="count">排序数量</param>
        internal static void Random <valueType>(valueType[] values, int count)
        {
            AutoCSer.Random random = AutoCSer.Random.Default;
            valueType       value;
            int             index;

            while (count > 1)
            {
                index         = (int)((uint)random.Next() % (uint)count);
                value         = values[--count];
                values[count] = values[index];
                values[index] = value;
            }
        }
Exemple #2
0
 /// <summary>
 /// 创建集合测试
 /// </summary>
 private static void createSet()
 {
     try
     {
         removeCount = 0;
         AutoCSer.Random random   = AutoCSer.Random.Default;
         int             keyIndex = keyCount;
         time.Restart();
         for (int nextCount = count; nextCount > keyIndex; --nextCount)
         {
             int index = (int)((uint)random.Next() & (keyCount - 1)), key = keys[index];
             if (index < keyIndex)
             {
                 if (!set.Add(ref key))
                 {
                     isError = true;
                     Console.WriteLine("ERROR");
                     return;
                 }
                 if (set.Count != keyCount - keyIndex + 1)
                 {
                     isError = true;
                     Console.WriteLine("ERROR");
                     return;
                 }
                 keys[index]    = keys[--keyIndex];
                 keys[keyIndex] = key;
             }
             else
             {
                 if (!set.Remove(ref key))
                 {
                     isError = true;
                     Console.WriteLine("ERROR");
                     return;
                 }
                 if (set.Count != keyCount - keyIndex - 1)
                 {
                     isError = true;
                     Console.WriteLine("ERROR");
                     return;
                 }
                 keys[index] = keys[keyIndex];
                 ++removeCount;
                 keys[keyIndex++] = key;
             }
         }
         while (keyIndex != 0)
         {
             int index = (int)((uint)random.Next() % keyIndex), key = keys[index];
             if (!set.Add(ref key))
             {
                 isError = true;
                 Console.WriteLine("ERROR");
                 return;
             }
             if (set.Count != keyCount - keyIndex + 1)
             {
                 isError = true;
                 Console.WriteLine("ERROR");
                 return;
             }
             keys[index]    = keys[--keyIndex];
             keys[keyIndex] = key;
         }
         time.Stop();
         if (set.Count != keyCount)
         {
             isError = true;
             Console.WriteLine("ERROR");
             return;
         }
         for (int index = keyCount; index != 0;)
         {
             --index;
             if (set.At(index) != index)
             {
                 isError = true;
                 Console.WriteLine("ERROR");
                 return;
             }
         }
     }
     finally
     {
         wait.Set();
     }
 }