Ejemplo n.º 1
0
 public void TestOddEvenSort()
 {
     for (int t = 0; t < 10; t++)
     {
         var arr = new int[_random.Next(100, 200)];
         for (int i = 0; i < arr.Length; i++)
         {
             arr[i] = _random.Next();
         }
         var arr1 = new int[arr.Length];
         var arr2 = new int[arr.Length];
         for (int i = 0; i < arr.Length; i++)
         {
             arr1[i] = arr[i];
         }
         for (int i = 0; i < arr.Length; i++)
         {
             arr2[i] = arr[i];
         }
         Array.Sort(arr1);
         lock (CudafyArray.Semaphore)
         {
             CudafyArray.SetArray(arr2);
             CudafyArray.OddEvenSort();
             arr2 = CudafyArray.GetArray();
         }
         Console.WriteLine(string.Join(",", arr1.Select(i => i.ToString(CultureInfo.InvariantCulture))));
         Console.WriteLine(string.Join(",", arr2.Select(i => i.ToString(CultureInfo.InvariantCulture))));
         Assert.IsTrue(arr1.SequenceEqual(arr2));
     }
 }
Ejemplo n.º 2
0
 public override int GetHashCode()
 {
     if (Settings.EnableCudafy)
     {
         try
         {
             lock (CudafyArray.Semaphore)
             {
                 CudafyArray.SetArray(this.Select(item => item.GetHashCode()).ToArray());
                 CudafyArray.Execute("Hash");
                 return(CudafyArray.GetHash());
             }
         }
         catch (Exception ex)
         {
             Debug.WriteLine(ex.ToString());
             return(this.Aggregate(0,
                                   (current, item) => (current << 1) ^ (current >> (8 * sizeof(int) - 1)) ^ item.GetHashCode()));
         }
     }
     return(this.Aggregate(0,
                           (current, item) => (current << 1) ^ (current >> (8 * sizeof(int) - 1)) ^ item.GetHashCode()));
 }