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