暫無描述
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.

NativeHashSetExtensions.tt 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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
  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. ( "FixedList128Bytes" ),
  21. ( "FixedList32Bytes" ),
  22. ( "FixedList4096Bytes" ),
  23. ( "FixedList512Bytes" ),
  24. ( "FixedList64Bytes" ),
  25. ( "NativeArray" ),
  26. ( "NativeHashSet" ),
  27. ( "NativeList" ),
  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 <#=ContainerType#><T> container, <#=OtherContainerType#><T> other)
  37. where T : unmanaged, IEquatable<T>
  38. {
  39. foreach (var item in other)
  40. {
  41. container.Remove(item);
  42. }
  43. }
  44. /// <summary>
  45. /// Removes the values from this set which are absent in another collection.
  46. /// </summary>
  47. /// <typeparam name="T">The type of values.</typeparam>
  48. /// <param name="container">The set to remove values from.</param>
  49. /// <param name="other">The collection to compare with.</param>
  50. public static void IntersectWith<T>(this <#=ContainerType#><T> container, <#=OtherContainerType#><T> other)
  51. where T : unmanaged, IEquatable<T>
  52. {
  53. var result = new UnsafeList<T>(container.Count(), Allocator.Temp);
  54. foreach (var item in other)
  55. {
  56. if (container.Contains(item))
  57. {
  58. result.Add(item);
  59. }
  60. }
  61. container.Clear();
  62. container.UnionWith(result);
  63. result.Dispose();
  64. }
  65. /// <summary>
  66. /// Adds all values from a collection to this set.
  67. /// </summary>
  68. /// <typeparam name="T">The type of values.</typeparam>
  69. /// <param name="container">The set to add values to.</param>
  70. /// <param name="other">The collection to copy values from.</param>
  71. public static void UnionWith<T>(this <#=ContainerType#><T> container, <#=OtherContainerType#><T> other)
  72. where T : unmanaged, IEquatable<T>
  73. {
  74. foreach (var item in other)
  75. {
  76. container.Add(item);
  77. }
  78. }
  79. <#}}}#>
  80. }
  81. }