/// <summary>
        /// Sorts the elements of this query.
        /// </summary>
        /// <typeparam name="T">Type of the elements.</typeparam>
        /// <param name="query">The query.</param>
        /// <param name="comparison">The comparison.</param>
        /// <returns>This query with the elements sorted.</returns>
        unsafe public static NativeQuery <T> Sorted <T>(this NativeQuery <T> query, Comparison <T> comparison) where T : unmanaged
        {
            if (query.IsEmpty)
            {
                return(new NativeQuery <T>(query.GetAllocator()));
            }

            NativeSortUtilities.Sort(query._buffer, query.Length, comparison);
            return(query);
        }
        /// <summary>
        /// Sorts the elements of this query.
        /// </summary>
        /// <typeparam name="T">Type of the elements.</typeparam>
        /// <param name="query">The query.</param>
        /// <returns>This query with the elements sorted.</returns>
        unsafe public static NativeQuery <T> Sorted <T>(this NativeQuery <T> query) where T : unmanaged, IComparable <T>
        {
            if (query.IsEmpty)
            {
                return(new NativeQuery <T>(query.GetAllocator()));
            }

            NativeSortUtilities.Sort <T>(query._buffer, query.Length);
            return(query);
        }
        /// <summary>
        /// Sorts by decending the content of this array.
        /// </summary>
        /// <typeparam name="T">Type of the elements</typeparam>
        /// <typeparam name="TSelect">The type of the key used for sorting</typeparam>
        /// <param name="array">The array to sort.</param>
        /// <param name="start">The start index.</param>
        /// <param name="end">The end index.</param>
        /// <param name="comparer">The comparer used for sorting</param>
        /// <param name="selector">The selects the key used for sort.</param>
        /// <exception cref="ArgumentException">If the array is invalid</exception>
        /// <exception cref="ArgumentOutOfRangeException">If the specified range is invalid</exception>
        public static void SortByDecending <T, TSelect>(this NativeArray <T> array, int start, int end, IComparer <TSelect> comparer, Func <T, TSelect> selector) where T : unmanaged
        {
            if (!array.IsValid)
            {
                throw new ArgumentException("NativeArray is invalid");
            }

            if (start > end || start < 0 || end < 0 || start > array.Length || end > array.Length)
            {
                throw new ArgumentOutOfRangeException($"Invalid range, start: {start}, end: {end}");
            }

            NativeSortUtilities.SortBy(array._buffer, start, end, true, comparer, selector);
        }
        /// <summary>
        /// Sorts the content of this array.
        /// </summary>
        /// <typeparam name="T">Type of the elements</typeparam>
        /// <param name="array">The array to sort.</param>
        /// <param name="start">The start index.</param>
        /// <param name="end">The end index.</param>
        /// <param name="comparison">Used for compare the elements to sort.</param>
        /// <exception cref="ArgumentException">If the array is invalid</exception>
        /// <exception cref="ArgumentOutOfRangeException">If the specified range is invalid</exception>
        public static void Sort <T>(this NativeArray <T> array, int start, int end, Comparison <T> comparison) where T : unmanaged
        {
            if (!array.IsValid)
            {
                throw new ArgumentException("NativeArray is invalid");
            }

            if (start > end || start < 0 || end < 0 || start > array.Length || end > array.Length)
            {
                throw new ArgumentOutOfRangeException($"Invalid range, start: {start}, end: {end}");
            }

            void *pointer = array._buffer;

            NativeSortUtilities.Sort(pointer, start, end, false, comparison);
        }
Beispiel #5
0
        /// <summary>
        /// Sorts the content of this list.
        /// </summary>
        /// <typeparam name="T">Type of the elements</typeparam>
        /// <param name="list">The list to sort.</param>
        /// <param name="start">The start index.</param>
        /// <param name="end">The end index.</param>
        /// <param name="comparer">The comparer to use.</param>
        /// <exception cref="ArgumentException">If the list is invalid</exception>
        /// <exception cref="ArgumentOutOfRangeException">If the specified range is invalid</exception>
        public static void Sort <T>(this NativeList <T> list, int start, int end, IComparer <T> comparer) where T : unmanaged
        {
            if (!list.IsValid)
            {
                throw new ArgumentException("NativeList is invalid");
            }

            if (start > end || start < 0 || end < 0 || start > list.Length || end > list.Length)
            {
                throw new ArgumentOutOfRangeException($"Invalid range, start: {start}, end: {end}");
            }

            void *pointer = list._buffer;

            NativeSortUtilities.Sort(pointer, start, end, false, comparer);
        }