//#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.
[NotBurstCompatible]
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.
[NotBurstCompatible]
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.
[NotBurstCompatible]
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);
}
#if !NET_DOTS // Tuple is not supported by TinyBCL
///
/// Returns an array with the unique keys of this multi hash map.
///
/// The type of the keys.
/// The type of the values.
/// The multi hash map.
/// The allocator to use.
/// An array with the unique keys of this multi hash map.
[BurstCompatible(GenericTypeArguments = new[] { typeof(int), typeof(int) })]
[Obsolete("Burst now supports tuple, please use `GetUniqueKeyArray` method from `Unity.Collections.UnsafeParallelMultiHashMap` instead.", false)]
public static (NativeArray, int) GetUniqueKeyArrayNBC(this UnsafeParallelMultiHashMap hashmap, AllocatorManager.AllocatorHandle allocator)
where TKey : struct, IEquatable, IComparable
where TValue : struct => hashmap.GetUniqueKeyArray(allocator);
///
/// Returns an array with the unique keys of this multi hash map.
///
/// The type of the keys.
/// The type of the values.
/// The multi hash map.
/// The allocator to use.
/// An array with the unique keys of this multi hash map.
[BurstCompatible(GenericTypeArguments = new[] { typeof(int), typeof(int) })]
[Obsolete("Burst now supports tuple, please use `GetUniqueKeyArray` method from `Unity.Collections.NativeParallelMultiHashMap` instead.", false)]
public static (NativeArray, int) GetUniqueKeyArrayNBC(this NativeParallelMultiHashMap hashmap, AllocatorManager.AllocatorHandle allocator)
where TKey : struct, IEquatable, IComparable
where TValue : struct => hashmap.GetUniqueKeyArray(allocator);
#endif
}
}