Няма описание
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.

UnsafeHashSetExtensions.tt 5.2KB

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