Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlBinaryWriterSession.cs
Go to the documentation of this file.
4
5namespace System.Xml;
6
8{
9 private sealed class PriorityDictionary<K, V> where K : class
10 {
11 private struct Entry
12 {
13 public K Key;
14
15 public V Value;
16
17 public int Time;
18 }
19
21
22 private readonly Entry[] _list;
23
24 private int _listCount;
25
26 private int _now;
27
28 private int Now
29 {
30 get
31 {
32 if (++_now == int.MaxValue)
33 {
35 }
36 return _now;
37 }
38 }
39
41 {
42 _list = new Entry[16];
43 }
44
45 public void Clear()
46 {
47 _now = 0;
48 _listCount = 0;
50 if (_dictionary != null)
51 {
53 }
54 }
55
56 public bool TryGetValue(K key, [MaybeNullWhen(false)] out V value)
57 {
58 for (int i = 0; i < _listCount; i++)
59 {
60 if (_list[i].Key == key)
61 {
62 value = _list[i].Value;
63 _list[i].Time = Now;
64 return true;
65 }
66 }
67 for (int j = 0; j < _listCount; j++)
68 {
69 if (_list[j].Key.Equals(key))
70 {
71 value = _list[j].Value;
72 _list[j].Time = Now;
73 return true;
74 }
75 }
76 if (_dictionary == null)
77 {
78 value = default(V);
79 return false;
80 }
82 {
83 return false;
84 }
85 int num = 0;
86 int time = _list[0].Time;
87 for (int k = 1; k < _listCount; k++)
88 {
89 if (_list[k].Time < time)
90 {
91 num = k;
92 time = _list[k].Time;
93 }
94 }
95 _list[num].Key = key;
96 _list[num].Value = value;
97 _list[num].Time = Now;
98 return true;
99 }
100
101 public void Add(K key, V value)
102 {
103 if (_listCount < _list.Length)
104 {
107 _listCount++;
108 return;
109 }
110 if (_dictionary == null)
111 {
113 for (int i = 0; i < _listCount; i++)
114 {
115 _dictionary.Add(_list[i].Key, _list[i].Value);
116 }
117 }
119 }
120
121 private void DecreaseAll()
122 {
123 for (int i = 0; i < _listCount; i++)
124 {
125 _list[i].Time /= 2;
126 }
127 _now /= 2;
128 }
129 }
130
131 private sealed class IntArray
132 {
133 private int[] _array;
134
135 public int this[int index]
136 {
137 get
138 {
139 if (index >= _array.Length)
140 {
141 return 0;
142 }
143 return _array[index];
144 }
145 set
146 {
147 if (index >= _array.Length)
148 {
149 int[] array = new int[Math.Max(index + 1, _array.Length * 2)];
150 Array.Copy(_array, array, _array.Length);
151 _array = array;
152 }
153 _array[index] = value;
154 }
155 }
156
157 public IntArray(int size)
158 {
159 _array = new int[size];
160 }
161 }
162
164
166
167 private int _nextKey;
168
175
176 public virtual bool TryAdd(XmlDictionaryString value, out int key)
177 {
178 if (value == null)
179 {
181 }
182 if (_maps.TryGetValue(value.Dictionary, out var value2))
183 {
184 key = value2[value.Key] - 1;
185 if (key != -1)
186 {
188 }
189 key = Add(value.Value);
190 value2[value.Key] = key + 1;
191 return true;
192 }
193 key = Add(value.Value);
194 value2 = AddKeys(value.Dictionary, value.Key + 1);
195 value2[value.Key] = key + 1;
196 return true;
197 }
198
199 private int Add(string s)
200 {
201 int num = _nextKey++;
202 _strings.Add(s, num);
203 return num;
204 }
205
212
213 public void Reset()
214 {
215 _nextKey = 0;
216 _maps.Clear();
217 _strings.Clear();
218 }
219
221 {
222 if (_maps.TryGetValue(s.Dictionary, out var value))
223 {
224 key = value[s.Key] - 1;
225 if (key != -1)
226 {
227 return true;
228 }
229 }
230 if (_strings.TryGetValue(s.Value, out key))
231 {
232 if (value == null)
233 {
234 value = AddKeys(s.Dictionary, s.Key + 1);
235 }
236 value[s.Key] = key + 1;
237 return true;
238 }
239 key = -1;
240 return false;
241 }
242}
static unsafe void Clear(Array array)
Definition Array.cs:755
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void Add(TKey key, TValue value)
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static string XmlKeyAlreadyExists
Definition SR.cs:412
Definition SR.cs:7
bool TryGetValue(K key, [MaybeNullWhen(false)] out V value)
bool TryLookup(XmlDictionaryString s, out int key)
virtual bool TryAdd(XmlDictionaryString value, out int key)
readonly PriorityDictionary< IXmlDictionary, IntArray > _maps
IntArray AddKeys(IXmlDictionary dictionary, int minCount)
readonly PriorityDictionary< string, int > _strings