Geen omschrijving
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UnsafeParallelHashSetExtensions.tt 5.9KB

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