A game about forced loneliness, made by TACStudios
at master 168 lines 6.0 kB view raw
1<#/*THIS IS A T4 FILE - see t4_text_templating.md for what it is and how to run codegen*/#> 2<#@ template debug="True" #> 3<#@ output extension=".gen.cs" #> 4<#@ assembly name="System.Core" #> 5using System; 6using Unity.Collections.LowLevel.Unsafe; 7 8namespace Unity.Collections.LowLevel.Unsafe 9{ 10 /// <summary> 11 /// Provides extension methods for sets. 12 /// </summary> 13 public unsafe static class HashSetExtensions 14 { 15<# 16{ 17 foreach (var ContainerType in new[] { 18 ( new[] { "NativeHashSet", "Count" } ), 19 ( new[] { "NativeParallelHashSet", "Count()" } ), 20 }) { 21 22 foreach (var OtherContainerType in new[] { 23 ( "UnsafeHashSet<T>" ), 24 ( "UnsafeHashSet<T>.ReadOnly" ), 25 ( "UnsafeParallelHashSet<T>" ), 26 ( "UnsafeParallelHashSet<T>.ReadOnly" ), 27 ( "UnsafeList<T>" ), 28 }) { 29#> 30 /// <summary> 31 /// Removes the values from this set which are also present in another collection. 32 /// </summary> 33 /// <typeparam name="T">The type of values.</typeparam> 34 /// <param name="container">The set to remove values from.</param> 35 /// <param name="other">The collection to compare with.</param> 36 public static void ExceptWith<T>(this ref <#=ContainerType[0]#><T> container, <#=OtherContainerType#> other) 37 where T : unmanaged, IEquatable<T> 38 { 39 foreach (var item in other) 40 { 41 container.Remove(item); 42 } 43 } 44 45 /// <summary> 46 /// Removes the values from this set which are absent in another collection. 47 /// </summary> 48 /// <typeparam name="T">The type of values.</typeparam> 49 /// <param name="container">The set to remove values from.</param> 50 /// <param name="other">The collection to compare with.</param> 51 public static void IntersectWith<T>(this ref <#=ContainerType[0]#><T> container, <#=OtherContainerType#> other) 52 where T : unmanaged, IEquatable<T> 53 { 54 var result = new UnsafeList<T>(container.<#=ContainerType[1]#>, Allocator.Temp); 55 56 foreach (var item in other) 57 { 58 if (container.Contains(item)) 59 { 60 result.Add(item); 61 } 62 } 63 64 container.Clear(); 65 container.UnionWith(result); 66 67 result.Dispose(); 68 } 69 70 /// <summary> 71 /// Adds all values from a collection to this set. 72 /// </summary> 73 /// <typeparam name="T">The type of values.</typeparam> 74 /// <param name="container">The set to add values to.</param> 75 /// <param name="other">The collection to copy values from.</param> 76 public static void UnionWith<T>(this ref <#=ContainerType[0]#><T> container, <#=OtherContainerType#> other) 77 where T : unmanaged, IEquatable<T> 78 { 79 foreach (var item in other) 80 { 81 container.Add(item); 82 } 83 } 84<#}}}#> 85 86<# 87{ 88 foreach (var ContainerType in new[] { 89 ( new[] { "UnsafeHashSet", "Count" } ), 90 ( new[] { "UnsafeParallelHashSet", "Count()" } ), 91 }) { 92 93 foreach (var OtherContainerType in new[] { 94 ( "FixedList128Bytes<T>" ), 95 ( "FixedList32Bytes<T>" ), 96 ( "FixedList4096Bytes<T>" ), 97 ( "FixedList512Bytes<T>" ), 98 ( "FixedList64Bytes<T>" ), 99 ( "NativeArray<T>" ), 100 ( "NativeHashSet<T>" ), 101 ( "NativeHashSet<T>.ReadOnly" ), 102 ( "UnsafeHashSet<T>"), 103 ( "UnsafeHashSet<T>.ReadOnly"), 104 ( "NativeParallelHashSet<T>" ), 105 ( "NativeParallelHashSet<T>.ReadOnly" ), 106 ( "UnsafeParallelHashSet<T>" ), 107 ( "UnsafeParallelHashSet<T>.ReadOnly" ), 108 ( "NativeList<T>" ), 109 ( "UnsafeList<T>" ), 110 }) { 111#> 112 /// <summary> 113 /// Removes the values from this set which are also present in another collection. 114 /// </summary> 115 /// <typeparam name="T">The type of values.</typeparam> 116 /// <param name="container">The set to remove values from.</param> 117 /// <param name="other">The collection to compare with.</param> 118 public static void ExceptWith<T>(this ref <#=ContainerType[0]#><T> container, <#=OtherContainerType#> other) 119 where T : unmanaged, IEquatable<T> 120 { 121 foreach (var item in other) 122 { 123 container.Remove(item); 124 } 125 } 126 127 /// <summary> 128 /// Removes the values from this set which are absent in another collection. 129 /// </summary> 130 /// <typeparam name="T">The type of values.</typeparam> 131 /// <param name="container">The set to remove values from.</param> 132 /// <param name="other">The collection to compare with.</param> 133 public static void IntersectWith<T>(this ref <#=ContainerType[0]#><T> container, <#=OtherContainerType#> other) 134 where T : unmanaged, IEquatable<T> 135 { 136 var result = new UnsafeList<T>(container.<#=ContainerType[1]#>, Allocator.Temp); 137 138 foreach (var item in other) 139 { 140 if (container.Contains(item)) 141 { 142 result.Add(item); 143 } 144 } 145 146 container.Clear(); 147 container.UnionWith(result); 148 149 result.Dispose(); 150 } 151 152 /// <summary> 153 /// Adds all values from a collection to this set. 154 /// </summary> 155 /// <typeparam name="T">The type of values.</typeparam> 156 /// <param name="container">The set to add values to.</param> 157 /// <param name="other">The collection to copy values from.</param> 158 public static void UnionWith<T>(this ref <#=ContainerType[0]#><T> container, <#=OtherContainerType#> other) 159 where T : unmanaged, IEquatable<T> 160 { 161 foreach (var item in other) 162 { 163 container.Add(item); 164 } 165 } 166<#}}}#> 167 } 168}