Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ListDictionary.cs
Go to the documentation of this file.
2
4
6[TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
8{
10 {
11 private readonly ListDictionary _list;
12
14
15 private readonly int _version;
16
17 private bool _start;
18
19 public object Current => Entry;
20
22 {
23 get
24 {
25 if (_current == null)
26 {
28 }
30 }
31 }
32
33 public object Key
34 {
35 get
36 {
37 if (_current == null)
38 {
40 }
41 return _current.key;
42 }
43 }
44
45 public object Value
46 {
47 get
48 {
49 if (_current == null)
50 {
52 }
53 return _current.value;
54 }
55 }
56
58 {
59 _list = list;
60 _version = list.version;
61 _start = true;
62 _current = null;
63 }
64
65 public bool MoveNext()
66 {
67 if (_version != _list.version)
68 {
70 }
71 if (_start)
72 {
74 _start = false;
75 }
76 else if (_current != null)
77 {
79 }
80 return _current != null;
81 }
82
83 public void Reset()
84 {
85 if (_version != _list.version)
86 {
88 }
89 _start = true;
90 _current = null;
91 }
92 }
93
95 {
96 private sealed class NodeKeyValueEnumerator : IEnumerator
97 {
98 private readonly ListDictionary _list;
99
101
102 private readonly int _version;
103
104 private readonly bool _isKeys;
105
106 private bool _start;
107
108 public object Current
109 {
110 get
111 {
112 if (_current == null)
113 {
115 }
116 if (!_isKeys)
117 {
118 return _current.value;
119 }
120 return _current.key;
121 }
122 }
123
125 {
126 _list = list;
127 _isKeys = isKeys;
128 _version = list.version;
129 _start = true;
130 _current = null;
131 }
132
133 public bool MoveNext()
134 {
135 if (_version != _list.version)
136 {
138 }
139 if (_start)
140 {
142 _start = false;
143 }
144 else if (_current != null)
145 {
147 }
148 return _current != null;
149 }
150
151 public void Reset()
152 {
153 if (_version != _list.version)
154 {
156 }
157 _start = true;
158 _current = null;
159 }
160 }
161
162 private readonly ListDictionary _list;
163
164 private readonly bool _isKeys;
165
166 int ICollection.Count
167 {
168 get
169 {
170 int num = 0;
171 for (DictionaryNode dictionaryNode = _list.head; dictionaryNode != null; dictionaryNode = dictionaryNode.next)
172 {
173 num++;
174 }
175 return num;
176 }
177 }
178
179 bool ICollection.IsSynchronized => false;
180
181 object ICollection.SyncRoot => _list.SyncRoot;
182
184 {
185 _list = list;
186 _isKeys = isKeys;
187 }
188
190 {
191 if (array == null)
192 {
193 throw new ArgumentNullException("array");
194 }
195 if (index < 0)
196 {
198 }
199 for (DictionaryNode dictionaryNode = _list.head; dictionaryNode != null; dictionaryNode = dictionaryNode.next)
200 {
201 array.SetValue(_isKeys ? dictionaryNode.key : dictionaryNode.value, index);
202 index++;
203 }
204 }
205
210 }
211
212 [Serializable]
213 [TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
214 public class DictionaryNode
215 {
216 public object key;
217
218 public object? value;
219
221 }
222
224
225 private int version;
226
227 private int count;
228
229 private readonly IComparer comparer;
230
231 public object? this[object key]
232 {
233 get
234 {
235 if (key == null)
236 {
237 throw new ArgumentNullException("key");
238 }
239 DictionaryNode next = head;
240 if (comparer == null)
241 {
242 while (next != null)
243 {
244 object key2 = next.key;
245 if (key2.Equals(key))
246 {
247 return next.value;
248 }
249 next = next.next;
250 }
251 }
252 else
253 {
254 while (next != null)
255 {
256 object key3 = next.key;
257 if (comparer.Compare(key3, key) == 0)
258 {
259 return next.value;
260 }
261 next = next.next;
262 }
263 }
264 return null;
265 }
266 set
267 {
268 if (key == null)
269 {
270 throw new ArgumentNullException("key");
271 }
272 version++;
273 DictionaryNode dictionaryNode = null;
274 DictionaryNode next;
275 for (next = head; next != null; next = next.next)
276 {
277 object key2 = next.key;
278 if ((comparer == null) ? key2.Equals(key) : (comparer.Compare(key2, key) == 0))
279 {
280 break;
281 }
282 dictionaryNode = next;
283 }
284 if (next != null)
285 {
286 next.value = value;
287 return;
288 }
289 DictionaryNode dictionaryNode2 = new DictionaryNode();
290 dictionaryNode2.key = key;
291 dictionaryNode2.value = value;
292 if (dictionaryNode != null)
293 {
294 dictionaryNode.next = dictionaryNode2;
295 }
296 else
297 {
298 head = dictionaryNode2;
299 }
300 count++;
301 }
302 }
303
304 public int Count => count;
305
306 public ICollection Keys => new NodeKeyValueCollection(this, isKeys: true);
307
308 public bool IsReadOnly => false;
309
310 public bool IsFixedSize => false;
311
312 public bool IsSynchronized => false;
313
314 public object SyncRoot => this;
315
316 public ICollection Values => new NodeKeyValueCollection(this, isKeys: false);
317
319 {
320 }
321
323 {
324 this.comparer = comparer;
325 }
326
327 public void Add(object key, object? value)
328 {
329 if (key == null)
330 {
331 throw new ArgumentNullException("key");
332 }
333 version++;
334 DictionaryNode dictionaryNode = null;
335 for (DictionaryNode next = head; next != null; next = next.next)
336 {
337 object key2 = next.key;
338 if ((comparer == null) ? key2.Equals(key) : (comparer.Compare(key2, key) == 0))
339 {
341 }
342 dictionaryNode = next;
343 }
344 DictionaryNode dictionaryNode2 = new DictionaryNode();
345 dictionaryNode2.key = key;
346 dictionaryNode2.value = value;
347 if (dictionaryNode != null)
348 {
349 dictionaryNode.next = dictionaryNode2;
350 }
351 else
352 {
353 head = dictionaryNode2;
354 }
355 count++;
356 }
357
358 public void Clear()
359 {
360 count = 0;
361 head = null;
362 version++;
363 }
364
365 public bool Contains(object key)
366 {
367 if (key == null)
368 {
369 throw new ArgumentNullException("key");
370 }
371 for (DictionaryNode next = head; next != null; next = next.next)
372 {
373 object key2 = next.key;
374 if ((comparer == null) ? key2.Equals(key) : (comparer.Compare(key2, key) == 0))
375 {
376 return true;
377 }
378 }
379 return false;
380 }
381
382 public void CopyTo(Array array, int index)
383 {
384 if (array == null)
385 {
386 throw new ArgumentNullException("array");
387 }
388 if (index < 0)
389 {
391 }
392 if (array.Length - index < count)
393 {
395 }
396 for (DictionaryNode next = head; next != null; next = next.next)
397 {
398 array.SetValue(new DictionaryEntry(next.key, next.value), index);
399 index++;
400 }
401 }
402
404 {
405 return new NodeEnumerator(this);
406 }
407
409 {
410 return new NodeEnumerator(this);
411 }
412
413 public void Remove(object key)
414 {
415 if (key == null)
416 {
417 throw new ArgumentNullException("key");
418 }
419 version++;
420 DictionaryNode dictionaryNode = null;
421 DictionaryNode next;
422 for (next = head; next != null; next = next.next)
423 {
424 object key2 = next.key;
425 if ((comparer == null) ? key2.Equals(key) : (comparer.Compare(key2, key) == 0))
426 {
427 break;
428 }
429 dictionaryNode = next;
430 }
431 if (next != null)
432 {
433 if (next == head)
434 {
435 head = next.next;
436 }
437 else
438 {
439 dictionaryNode.next = next.next;
440 }
441 count--;
442 }
443 }
444}
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string ArgumentOutOfRange_NeedNonNegNum_Index
Definition SR.cs:18
static string Argument_AddingDuplicate
Definition SR.cs:14
static string InvalidOperation_EnumFailedVersion
Definition SR.cs:44
static string InvalidOperation_EnumOpCantHappen
Definition SR.cs:48
static string Arg_InsufficientSpace
Definition SR.cs:26
Definition SR.cs:7
void CopyTo(Array array, int index)
int Compare(object? x, object? y)