Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HybridReferenceDictionary.cs
Go to the documentation of this file.
3
5
6internal sealed class HybridReferenceDictionary<TKey, TValue> where TKey : class
7{
9
11
12 public TValue this[TKey key]
13 {
14 get
15 {
17 {
18 return value;
19 }
21 }
22 set
23 {
24 if (_dict != null)
25 {
26 _dict[key] = value;
27 return;
28 }
29 int num;
30 if (_keysAndValues != null)
31 {
32 num = -1;
33 for (int i = 0; i < _keysAndValues.Length; i++)
34 {
35 if (_keysAndValues[i].Key == key)
36 {
38 return;
39 }
40 if (_keysAndValues[i].Key == null)
41 {
42 num = i;
43 }
44 }
45 }
46 else
47 {
49 num = 0;
50 }
51 if (num != -1)
52 {
54 return;
55 }
57 for (int j = 0; j < _keysAndValues.Length; j++)
58 {
59 _dict[_keysAndValues[j].Key] = _keysAndValues[j].Value;
60 }
61 _keysAndValues = null;
62 _dict[key] = value;
63 }
64 }
65
66 public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
67 {
68 if (_dict != null)
69 {
70 return _dict.TryGetValue(key, out value);
71 }
72 if (_keysAndValues != null)
73 {
74 for (int i = 0; i < _keysAndValues.Length; i++)
75 {
76 if (_keysAndValues[i].Key == key)
77 {
78 value = _keysAndValues[i].Value;
79 return true;
80 }
81 }
82 }
83 value = default(TValue);
84 return false;
85 }
86
87 public void Remove(TKey key)
88 {
89 if (_dict != null)
90 {
91 _dict.Remove(key);
92 }
93 else
94 {
95 if (_keysAndValues == null)
96 {
97 return;
98 }
99 for (int i = 0; i < _keysAndValues.Length; i++)
100 {
101 if (_keysAndValues[i].Key == key)
102 {
104 break;
105 }
106 }
107 }
108 }
109
110 public bool ContainsKey(TKey key)
111 {
112 if (_dict != null)
113 {
114 return _dict.ContainsKey(key);
115 }
117 if (keysAndValues != null)
118 {
119 for (int i = 0; i < keysAndValues.Length; i++)
120 {
121 if (keysAndValues[i].Key == key)
122 {
123 return true;
124 }
125 }
126 }
127 return false;
128 }
129
131 {
132 if (_dict != null)
133 {
134 return _dict.GetEnumerator();
135 }
136 return GetEnumeratorWorker();
137 }
138
140 {
141 if (_keysAndValues == null)
142 {
143 yield break;
144 }
145 for (int i = 0; i < _keysAndValues.Length; i++)
146 {
147 if (_keysAndValues[i].Key != null)
148 {
149 yield return _keysAndValues[i];
150 }
151 }
152 }
153}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
IEnumerator< KeyValuePair< TKey, TValue > > GetEnumeratorWorker()
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Arg_KeyNotFoundWithKey
Definition SR.cs:94
Definition SR.cs:7