//#define USE_NOT_BURST_COMPATIBLE_EXTENSIONS
using System;
using Unity.Collections.LowLevel.Unsafe;
namespace Unity.Collections.NotBurstCompatible
{
    /// 
    /// Provides some extension methods for various collections.
    /// 
    public static class Extensions
    {
        /// 
        /// Returns a new managed array with all the elements copied from a set.
        /// 
        /// The type of elements.
        /// The set whose elements are copied to the array.
        /// A new managed array with all the elements copied from a set.
        [ExcludeFromBurstCompatTesting("Returns managed array")]
        public static T[] ToArray(this NativeHashSet set)
            where T : unmanaged, IEquatable
        {
            var array = set.ToNativeArray(Allocator.TempJob);
            var managed = array.ToArray();
            array.Dispose();
            return managed;
        }
        /// 
        /// Returns a new managed array with all the elements copied from a set.
        /// 
        /// The type of elements.
        /// The set whose elements are copied to the array.
        /// A new managed array with all the elements copied from a set.
        [ExcludeFromBurstCompatTesting("Returns managed array")]
        public static T[] ToArray(this NativeParallelHashSet set)
            where T : unmanaged, IEquatable
        {
            var array = set.ToNativeArray(Allocator.TempJob);
            var managed = array.ToArray();
            array.Dispose();
            return managed;
        }
        /// 
        /// Returns a new managed array which is a copy of this list.
        /// 
        /// The type of elements.
        /// The list to copy.
        /// A new managed array which is a copy of this list.
        [ExcludeFromBurstCompatTesting("Returns managed array")]
        public static T[] ToArrayNBC(this NativeList list)
            where T : unmanaged
        {
            return list.AsArray().ToArray();
        }
        /// 
        /// Clears this list and then copies all the elements of an array to this list.
        /// 
        /// The type of elements.
        /// This list.
        /// The managed array to copy from.
        [ExcludeFromBurstCompatTesting("Takes managed array")]
        public static void CopyFromNBC(this NativeList list, T[] array)
            where T : unmanaged
        {
            list.Clear();
            list.Resize(array.Length, NativeArrayOptions.UninitializedMemory);
            NativeArray na = list.AsArray();
            na.CopyFrom(array);
        }
    }
}