A game about forced loneliness, made by TACStudios
1using System;
2using System.Collections;
3using System.Collections.Generic;
4
5namespace Unity.VisualScripting
6{
7 public class NonNullableHashSet<T> : ISet<T>
8 {
9 public NonNullableHashSet()
10 {
11 set = new HashSet<T>();
12 }
13
14 public NonNullableHashSet(IEqualityComparer<T> comparer)
15 {
16 set = new HashSet<T>(comparer);
17 }
18
19 public NonNullableHashSet(IEnumerable<T> collection)
20 {
21 set = new HashSet<T>(collection);
22 }
23
24 public NonNullableHashSet(IEnumerable<T> collection, IEqualityComparer<T> comparer)
25 {
26 set = new HashSet<T>(collection, comparer);
27 }
28
29 private readonly HashSet<T> set;
30
31 public int Count => set.Count;
32
33 public bool IsReadOnly => false;
34
35 public bool Add(T item)
36 {
37 if (item == null)
38 {
39 throw new ArgumentNullException(nameof(item));
40 }
41
42 return set.Add(item);
43 }
44
45 public void Clear()
46 {
47 set.Clear();
48 }
49
50 public bool Contains(T item)
51 {
52 if (item == null)
53 {
54 throw new ArgumentNullException(nameof(item));
55 }
56
57 return set.Contains(item);
58 }
59
60 public void CopyTo(T[] array, int arrayIndex)
61 {
62 set.CopyTo(array, arrayIndex);
63 }
64
65 public void ExceptWith(IEnumerable<T> other)
66 {
67 set.ExceptWith(other);
68 }
69
70 public IEnumerator<T> GetEnumerator()
71 {
72 return set.GetEnumerator();
73 }
74
75 public void IntersectWith(IEnumerable<T> other)
76 {
77 set.IntersectWith(other);
78 }
79
80 public bool IsProperSubsetOf(IEnumerable<T> other)
81 {
82 return set.IsProperSubsetOf(other);
83 }
84
85 public bool IsProperSupersetOf(IEnumerable<T> other)
86 {
87 return set.IsProperSupersetOf(other);
88 }
89
90 public bool IsSubsetOf(IEnumerable<T> other)
91 {
92 return set.IsSubsetOf(other);
93 }
94
95 public bool IsSupersetOf(IEnumerable<T> other)
96 {
97 return set.IsSupersetOf(other);
98 }
99
100 public bool Overlaps(IEnumerable<T> other)
101 {
102 return set.Overlaps(other);
103 }
104
105 public bool Remove(T item)
106 {
107 if (item == null)
108 {
109 throw new ArgumentNullException(nameof(item));
110 }
111
112 return set.Remove(item);
113 }
114
115 public bool SetEquals(IEnumerable<T> other)
116 {
117 return set.SetEquals(other);
118 }
119
120 public void SymmetricExceptWith(IEnumerable<T> other)
121 {
122 set.SymmetricExceptWith(other);
123 }
124
125 public void UnionWith(IEnumerable<T> other)
126 {
127 set.UnionWith(other);
128 }
129
130 void ICollection<T>.Add(T item)
131 {
132 if (item == null)
133 {
134 throw new ArgumentNullException(nameof(item));
135 }
136
137 ((ICollection<T>)set).Add(item);
138 }
139
140 IEnumerator IEnumerable.GetEnumerator()
141 {
142 return ((IEnumerable)set).GetEnumerator();
143 }
144 }
145}