Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

NativeParallelHashSetExtensions.tt 3.1KB

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