Ejemplo n.º 1
0
        public unsafe static void Sort <T, U>(this NativeSlice <T> slice, U comp) where T : struct where U : IComparer <T>
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (slice.Stride != UnsafeUtility.SizeOf <T>())
            {
                throw new InvalidOperationException("Sort requires that stride matches the size of the source type");
            }
#endif

            IntroSort <T, U>(slice.GetUnsafePtr(), slice.Length, comp);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Binary search for the value in the sorted container.
 /// </summary>
 /// <typeparam name="T">Source type of elements</typeparam>
 /// <typeparam name="U">The comparer type.</typeparam>
 /// <param name="container">The container to perform search.</param>
 /// <param name="value">The value to search for.</param>
 /// <returns>Positive index of the specified value if value is found. Otherwise bitwise complement of index of first greater value.</returns>
 /// <remarks>Array must be sorted, otherwise value searched might not be found even when it is in array. IComparer corresponds to IComparer used by sort.</remarks>
 public unsafe static int BinarySearch <T, U>(this NativeSlice <T> container, T value, U comp)
     where T : unmanaged
     where U : IComparer <T>
 {
     return(BinarySearch((T *)container.GetUnsafePtr(), container.Length, value, comp));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Sorts a slice using a custom comparison function.
 /// </summary>
 /// <typeparam name="T">Source type of elements</typeparam>
 /// <typeparam name="U">The comparer type.</typeparam>
 /// <param name="slice">List to perform sort.</param>
 /// <param name="comp">A comparison function that indicates whether one element in the array is less than, equal to, or greater than another element.</param>
 public unsafe static void Sort <T, U>(this NativeSlice <T> slice, U comp) where T : struct where U : IComparer <T>
 {
     CheckStrideMatchesSize <T>(slice.Stride);
     IntroSort <T, U>(slice.GetUnsafePtr(), slice.Length, comp);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Sorts the container using a custom comparison function.
 /// </summary>
 /// <typeparam name="T">Source type of elements</typeparam>
 /// <typeparam name="U">The comparer type.</typeparam>
 /// <param name="container">The container to perform sort.</param>
 /// <param name="comp">A comparison function that indicates whether one element in the array is less than, equal to, or greater than another element.</param>
 /// <param name="inputDeps">The job handle or handles for any scheduled jobs that use this container.</param>
 /// <returns>A new job handle containing the prior handles as well as the handle for the job that sorts
 /// the container.</returns>
 public unsafe static JobHandle Sort <T, U>(this NativeSlice <T> container, U comp, JobHandle inputDeps)
     where T : unmanaged
     where U : IComparer <T>
 {
     return(Sort((T *)container.GetUnsafePtr(), container.Length, comp, inputDeps));
 }