Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Lookup.cs
Go to the documentation of this file.
4
5namespace System.Linq;
6
7[DebuggerDisplay("Count = {Count}")]
9public class Lookup<TKey, TElement> : IIListProvider<IGrouping<TKey, TElement>>, IEnumerable<IGrouping<TKey, TElement>>, IEnumerable, ILookup<TKey, TElement>
10{
12
14
16
17 private int _count;
18
19 public int Count => _count;
20
21 public IEnumerable<TElement> this[TKey key]
22 {
23 get
24 {
27 return enumerable ?? Enumerable.Empty<TElement>();
28 }
29 }
30
32 {
34 int num = 0;
36 if (grouping != null)
37 {
38 do
39 {
41 num++;
42 }
43 while (grouping != _lastGrouping);
44 }
45 return array;
46 }
47
49 {
50 TResult[] array = new TResult[_count];
51 int num = 0;
53 if (grouping != null)
54 {
55 do
56 {
57 grouping = grouping._next;
58 grouping.Trim();
59 array[num] = resultSelector(grouping._key, grouping._elements);
60 num++;
61 }
62 while (grouping != _lastGrouping);
63 }
64 return array;
65 }
66
82
84 {
85 return _count;
86 }
87
97
107
109 {
111 foreach (TElement item in source)
112 {
113 TKey val = keySelector(item);
114 if (val != null)
115 {
116 lookup.GetGrouping(val, create: true).Add(item);
117 }
118 }
119 return lookup;
120 }
121
127
128 public bool Contains(TKey key)
129 {
130 return GetGrouping(key, create: false) != null;
131 }
132
134 {
136 if (g != null)
137 {
138 do
139 {
140 g = g._next;
141 yield return g;
142 }
143 while (g != _lastGrouping);
144 }
145 }
146
148 {
151 if (grouping != null)
152 {
153 do
154 {
155 grouping = grouping._next;
156 grouping.Trim();
157 list.Add(resultSelector(grouping._key, grouping._elements));
158 }
159 while (grouping != _lastGrouping);
160 }
161 return list;
162 }
163
165 {
167 if (g != null)
168 {
169 do
170 {
171 g = g._next;
172 g.Trim();
173 yield return resultSelector(g._key, g._elements);
174 }
175 while (g != _lastGrouping);
176 }
177 }
178
183
184 private int InternalGetHashCode(TKey key)
185 {
186 if (key != null)
187 {
188 return _comparer.GetHashCode(key) & 0x7FFFFFFF;
189 }
190 return 0;
191 }
192
194 {
195 int num = InternalGetHashCode(key);
196 for (Grouping<TKey, TElement> grouping = _groupings[num % _groupings.Length]; grouping != null; grouping = grouping._hashNext)
197 {
198 if (grouping._hashCode == num && _comparer.Equals(grouping._key, key))
199 {
200 return grouping;
201 }
202 }
203 if (create)
204 {
205 if (_count == _groupings.Length)
206 {
207 Resize();
208 }
209 int num2 = num % _groupings.Length;
211 grouping2._hashNext = _groupings[num2];
213 if (_lastGrouping == null)
214 {
215 grouping2._next = grouping2;
216 }
217 else
218 {
219 grouping2._next = _lastGrouping._next;
220 _lastGrouping._next = grouping2;
221 }
223 _count++;
224 return grouping2;
225 }
226 return null;
227 }
228
229 private void Resize()
230 {
231 int num = checked(_count * 2 + 1);
234 do
235 {
236 grouping = grouping._next;
237 int num2 = grouping._hashCode % num;
238 grouping._hashNext = array[num2];
240 }
241 while (grouping != _lastGrouping);
243 }
244}
void Add(TKey key, TValue value)
Grouping< TKey, TElement > _lastGrouping
Definition Lookup.cs:15
IEnumerator< IGrouping< TKey, TElement > > GetEnumerator()
Definition Lookup.cs:133
int InternalGetHashCode(TKey key)
Definition Lookup.cs:184
static Lookup< TKey, TElement > CreateForJoin(IEnumerable< TElement > source, Func< TElement, TKey > keySelector, IEqualityComparer< TKey > comparer)
Definition Lookup.cs:108
List< TResult > ToList< TResult >(Func< TKey, IEnumerable< TElement >, TResult > resultSelector)
Definition Lookup.cs:147
Grouping< TKey, TElement > GetGrouping(TKey key, bool create)
Definition Lookup.cs:193
readonly IEqualityComparer< TKey > _comparer
Definition Lookup.cs:11
IEnumerable< TResult > ApplyResultSelector< TResult >(Func< TKey, IEnumerable< TElement >, TResult > resultSelector)
Definition Lookup.cs:164
Grouping< TKey, TElement >[] _groupings
Definition Lookup.cs:13
static Lookup< TKey, TElement > Create< TSource >(IEnumerable< TSource > source, Func< TSource, TKey > keySelector, Func< TSource, TElement > elementSelector, IEqualityComparer< TKey > comparer)
Definition Lookup.cs:88
Lookup(IEqualityComparer< TKey > comparer)
Definition Lookup.cs:122
bool Contains(TKey key)
Definition Lookup.cs:128
TResult[] ToArray< TResult >(Func< TKey, IEnumerable< TElement >, TResult > resultSelector)
Definition Lookup.cs:48
static Lookup< TKey, TElement > Create(IEnumerable< TElement > source, Func< TElement, TKey > keySelector, IEqualityComparer< TKey > comparer)
Definition Lookup.cs:98
new IEnumerator< T > GetEnumerator()
new bool Equals(object? x, object? y)