Exemple #1
0
        /// <summary>
        /// Merge sort - non recursive
        /// </summary>
        /// <param name="arr">Array to sort.</param>
        /// <param name="sortSize">Size of the array to sort. If greater than array capacity, it will get clamped.</param>
        /// <param name="supportArray">Secondary array reference, used to store intermediate merge results.</param>
        public static unsafe void MergeSort(NativeArray <uint> arr, int sortSize, ref NativeArray <uint> supportArray)
        {
            sortSize = Math.Min(sortSize, arr.Length);
            if (!arr.IsCreated || sortSize == 0)
            {
                return;
            }

            if (!supportArray.IsCreated || supportArray.Length < sortSize)
            {
                supportArray.ResizeArray(arr.Length);
            }

            CoreUnsafeUtils.MergeSort((uint *)arr.GetUnsafePtr(), (uint *)supportArray.GetUnsafePtr(), sortSize);
        }
Exemple #2
0
        /// <summary>
        /// Merge sort - non recursive
        /// </summary>
        /// <param name="arr">Array to sort.</param>
        /// <param name="sortSize">Size of the array to sort. If greater than array capacity, it will get clamped.</param>
        /// <param name="supportArray">Secondary array reference, used to store intermediate merge results.</param>
        public static unsafe void MergeSort(uint[] arr, int sortSize, ref uint[] supportArray)
        {
            sortSize = Math.Min(sortSize, arr.Length);
            if (arr == null || sortSize == 0)
            {
                return;
            }

            if (supportArray == null || supportArray.Length < sortSize)
            {
                supportArray = new uint[sortSize];

                fixed(uint *arrPtr = arr)
                fixed(uint *supportPtr = supportArray)
                CoreUnsafeUtils.MergeSort(arrPtr, supportPtr, sortSize);
        }