<#/*THIS IS A T4 FILE - see t4_text_templating.md for what it is and how to run codegen*/#> <#@ template debug="True" #> <#@ output extension=".gen.cs" #> <#@ assembly name="System.Core" #> using System; using Unity.Collections.LowLevel.Unsafe; namespace Unity.Collections.LowLevel.Unsafe { /// /// Provides extension methods for sets. /// public unsafe static class HashSetExtensions { <# { foreach (var ContainerType in new[] { ( new[] { "NativeHashSet", "Count" } ), ( new[] { "NativeParallelHashSet", "Count()" } ), }) { foreach (var OtherContainerType in new[] { ( "UnsafeHashSet" ), ( "UnsafeHashSet.ReadOnly" ), ( "UnsafeParallelHashSet" ), ( "UnsafeParallelHashSet.ReadOnly" ), ( "UnsafeList" ), }) { #> /// /// Removes the values from this set which are also present in another collection. /// /// The type of values. /// The set to remove values from. /// The collection to compare with. public static void ExceptWith(this ref <#=ContainerType[0]#> container, <#=OtherContainerType#> other) where T : unmanaged, IEquatable { foreach (var item in other) { container.Remove(item); } } /// /// Removes the values from this set which are absent in another collection. /// /// The type of values. /// The set to remove values from. /// The collection to compare with. public static void IntersectWith(this ref <#=ContainerType[0]#> container, <#=OtherContainerType#> other) where T : unmanaged, IEquatable { var result = new UnsafeList(container.<#=ContainerType[1]#>, Allocator.Temp); foreach (var item in other) { if (container.Contains(item)) { result.Add(item); } } container.Clear(); container.UnionWith(result); result.Dispose(); } /// /// Adds all values from a collection to this set. /// /// The type of values. /// The set to add values to. /// The collection to copy values from. public static void UnionWith(this ref <#=ContainerType[0]#> container, <#=OtherContainerType#> other) where T : unmanaged, IEquatable { foreach (var item in other) { container.Add(item); } } <#}}}#> <# { foreach (var ContainerType in new[] { ( new[] { "UnsafeHashSet", "Count" } ), ( new[] { "UnsafeParallelHashSet", "Count()" } ), }) { foreach (var OtherContainerType in new[] { ( "FixedList128Bytes" ), ( "FixedList32Bytes" ), ( "FixedList4096Bytes" ), ( "FixedList512Bytes" ), ( "FixedList64Bytes" ), ( "NativeArray" ), ( "NativeHashSet" ), ( "NativeHashSet.ReadOnly" ), ( "UnsafeHashSet"), ( "UnsafeHashSet.ReadOnly"), ( "NativeParallelHashSet" ), ( "NativeParallelHashSet.ReadOnly" ), ( "UnsafeParallelHashSet" ), ( "UnsafeParallelHashSet.ReadOnly" ), ( "NativeList" ), ( "UnsafeList" ), }) { #> /// /// Removes the values from this set which are also present in another collection. /// /// The type of values. /// The set to remove values from. /// The collection to compare with. public static void ExceptWith(this ref <#=ContainerType[0]#> container, <#=OtherContainerType#> other) where T : unmanaged, IEquatable { foreach (var item in other) { container.Remove(item); } } /// /// Removes the values from this set which are absent in another collection. /// /// The type of values. /// The set to remove values from. /// The collection to compare with. public static void IntersectWith(this ref <#=ContainerType[0]#> container, <#=OtherContainerType#> other) where T : unmanaged, IEquatable { var result = new UnsafeList(container.<#=ContainerType[1]#>, Allocator.Temp); foreach (var item in other) { if (container.Contains(item)) { result.Add(item); } } container.Clear(); container.UnionWith(result); result.Dispose(); } /// /// Adds all values from a collection to this set. /// /// The type of values. /// The set to add values to. /// The collection to copy values from. public static void UnionWith(this ref <#=ContainerType[0]#> container, <#=OtherContainerType#> other) where T : unmanaged, IEquatable { foreach (var item in other) { container.Add(item); } } <#}}}#> } }