Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HybridDictionary.cs
Go to the documentation of this file.
2
4
6[TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
8{
10
12
13 private readonly bool caseInsensitive;
14
15 public object? this[object key]
16 {
17 get
18 {
19 ListDictionary listDictionary = list;
20 if (hashtable != null)
21 {
22 return hashtable[key];
23 }
24 if (listDictionary != null)
25 {
26 return listDictionary[key];
27 }
28 if (key == null)
29 {
30 throw new ArgumentNullException("key");
31 }
32 return null;
33 }
34 set
35 {
36 if (hashtable != null)
37 {
39 }
40 else if (list != null)
41 {
42 if (list.Count >= 8)
43 {
44 ChangeOver();
46 }
47 else
48 {
49 list[key] = value;
50 }
51 }
52 else
53 {
55 list[key] = value;
56 }
57 }
58 }
59
61 {
62 get
63 {
64 if (list == null)
65 {
67 }
68 return list;
69 }
70 }
71
72 public int Count
73 {
74 get
75 {
76 ListDictionary listDictionary = list;
77 if (hashtable != null)
78 {
79 return hashtable.Count;
80 }
81 return listDictionary?.Count ?? 0;
82 }
83 }
84
86 {
87 get
88 {
89 if (hashtable != null)
90 {
91 return hashtable.Keys;
92 }
93 return List.Keys;
94 }
95 }
96
97 public bool IsReadOnly => false;
98
99 public bool IsFixedSize => false;
100
101 public bool IsSynchronized => false;
102
103 public object SyncRoot => this;
104
106 {
107 get
108 {
109 if (hashtable != null)
110 {
111 return hashtable.Values;
112 }
113 return List.Values;
114 }
115 }
116
118 {
119 }
120
121 public HybridDictionary(int initialSize)
122 : this(initialSize, caseInsensitive: false)
123 {
124 }
125
127 {
128 this.caseInsensitive = caseInsensitive;
129 }
130
131 public HybridDictionary(int initialSize, bool caseInsensitive)
132 {
133 this.caseInsensitive = caseInsensitive;
134 if (initialSize >= 6)
135 {
136 if (caseInsensitive)
137 {
139 }
140 else
141 {
142 hashtable = new Hashtable(initialSize);
143 }
144 }
145 }
146
147 private void ChangeOver()
148 {
151 while (enumerator.MoveNext())
152 {
153 hashtable.Add(enumerator.Key, enumerator.Value);
154 }
155 this.hashtable = hashtable;
156 list = null;
157 }
158
159 public void Add(object key, object? value)
160 {
161 if (hashtable != null)
162 {
164 }
165 else if (list == null)
166 {
168 list.Add(key, value);
169 }
170 else if (list.Count + 1 >= 9)
171 {
172 ChangeOver();
174 }
175 else
176 {
177 list.Add(key, value);
178 }
179 }
180
181 public void Clear()
182 {
183 if (this.hashtable != null)
184 {
186 this.hashtable = null;
188 }
189 if (list != null)
190 {
191 ListDictionary listDictionary = list;
192 list = null;
193 listDictionary.Clear();
194 }
195 }
196
197 public bool Contains(object key)
198 {
199 ListDictionary listDictionary = list;
200 if (hashtable != null)
201 {
202 return hashtable.Contains(key);
203 }
204 if (listDictionary != null)
205 {
206 return listDictionary.Contains(key);
207 }
208 if (key == null)
209 {
210 throw new ArgumentNullException("key");
211 }
212 return false;
213 }
214
215 public void CopyTo(Array array, int index)
216 {
217 if (hashtable != null)
218 {
220 }
221 else
222 {
224 }
225 }
226
228 {
229 if (hashtable != null)
230 {
231 return hashtable.GetEnumerator();
232 }
233 if (list == null)
234 {
236 }
237 return list.GetEnumerator();
238 }
239
241 {
242 if (hashtable != null)
243 {
244 return hashtable.GetEnumerator();
245 }
246 if (list == null)
247 {
249 }
250 return list.GetEnumerator();
251 }
252
253 public void Remove(object key)
254 {
255 if (hashtable != null)
256 {
258 }
259 else if (list != null)
260 {
261 list.Remove(key);
262 }
263 else if (key == null)
264 {
265 throw new ArgumentNullException("key");
266 }
267 }
268}
virtual void CopyTo(Array array, int arrayIndex)
Definition Hashtable.cs:811
virtual bool Contains(object key)
Definition Hashtable.cs:719
IEnumerator IEnumerable. GetEnumerator()
Definition Hashtable.cs:899
virtual ICollection Values
Definition Hashtable.cs:534
virtual void Remove(object key)
virtual ICollection Keys
Definition Hashtable.cs:532
virtual void Add(object key, object? value)
Definition Hashtable.cs:676
HybridDictionary(int initialSize, bool caseInsensitive)
static StringComparer OrdinalIgnoreCase