Пример #1
0
        public void PartialSortInsertionMergeRadix(uint[] values)
        {
            NativeArray <uint> supportArray = new NativeArray <uint>();
            int sortCount = 5;

            foreach (var algorithmId in Enum.GetValues(typeof(SortAlgorithm)))
            {
                var algorithmValue = (SortAlgorithm)algorithmId;
                var array          = new NativeArray <uint>(values, Allocator.Temp);
                if (algorithmValue == SortAlgorithm.Insertion)
                {
                    CoreUnsafeUtils.InsertionSort(array, sortCount);
                }
                else if (algorithmValue == SortAlgorithm.Merge)
                {
                    CoreUnsafeUtils.MergeSort(array, sortCount, ref supportArray);
                }
                else if (algorithmValue == SortAlgorithm.Radix)
                {
                    CoreUnsafeUtils.RadixSort(array, sortCount, ref supportArray);
                }

                for (int i = 0; i < sortCount - 1; ++i)
                {
                    Assert.LessOrEqual(array[i], array[i + 1]);
                }
                for (int i = sortCount; i < array.Length; ++i)
                {
                    Assert.That(array[i] == 0 || array[i] == 1);
                }
                array.Dispose();
            }

            supportArray.Dispose();
        }
Пример #2
0
        public void MergeSort(uint[] values)
        {
            NativeArray <uint> supportArray = new NativeArray <uint>();
            var array = new NativeArray <uint>(values, Allocator.Temp);

            CoreUnsafeUtils.MergeSort(array, array.Length, ref supportArray);
            for (int i = 0; i < array.Length - 1; ++i)
            {
                Assert.LessOrEqual(array[i], array[i + 1]);
            }

            array.Dispose();
            supportArray.Dispose();
        }
 private void SortLightKeys()
 {
     using (new ProfilingScope(null, ProfilingSampler.Get(HDProfileId.SortVisibleLights)))
     {
         //Tunning against ps4 console,
         //32 items insertion sort has a workst case of 3 micro seconds.
         //200 non recursive merge sort has around 23 micro seconds.
         //From 200 and more, Radix sort beats everything.
         var sortSize = sortedLightCounts;
         if (sortSize <= 32)
         {
             CoreUnsafeUtils.InsertionSort(m_SortKeys, sortSize);
         }
         else if (m_Size <= 200)
         {
             CoreUnsafeUtils.MergeSort(m_SortKeys, sortSize, ref m_SortSupportArray);
         }
         else
         {
             CoreUnsafeUtils.RadixSort(m_SortKeys, sortSize, ref m_SortSupportArray);
         }
     }
 }