Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UInt16Storage.cs
Go to the documentation of this file.
3using System.Xml;
4
5namespace System.Data.Common;
6
7internal sealed class UInt16Storage : DataStorage
8{
9 private ushort[] _values;
10
12 : base(column, typeof(ushort), (ushort)0, StorageType.UInt16)
13 {
14 }
15
16 public override object Aggregate(int[] records, AggregateType kind)
17 {
18 bool flag = false;
19 try
20 {
21 switch (kind)
22 {
23 case AggregateType.Sum:
24 {
25 ulong num4 = 0uL;
26 foreach (int num5 in records)
27 {
28 if (HasValue(num5))
29 {
31 flag = true;
32 }
33 }
34 if (flag)
35 {
36 return num4;
37 }
38 return _nullValue;
39 }
40 case AggregateType.Mean:
41 {
42 long num11 = 0L;
43 int num12 = 0;
44 foreach (int num13 in records)
45 {
46 if (HasValue(num13))
47 {
49 num12++;
50 flag = true;
51 }
52 }
54 {
55 if (flag)
56 {
57 ushort num14 = (ushort)unchecked(num11 / num12);
58 return num14;
59 }
60 return _nullValue;
61 }
62 }
63 case AggregateType.Var:
64 case AggregateType.StDev:
65 {
66 int num = 0;
67 double num6 = 0.0;
68 double num7 = 0.0;
69 double num8 = 0.0;
70 double num9 = 0.0;
71 foreach (int num10 in records)
72 {
73 if (HasValue(num10))
74 {
75 num8 += (double)(int)_values[num10];
76 num9 += (double)(int)_values[num10] * (double)(int)_values[num10];
77 num++;
78 }
79 }
80 if (num > 1)
81 {
82 num6 = (double)num * num9 - num8 * num8;
83 num7 = num6 / (num8 * num8);
84 num6 = ((!(num7 < 1E-15) && !(num6 < 0.0)) ? (num6 / (double)(num * (num - 1))) : 0.0);
85 if (kind == AggregateType.StDev)
86 {
87 return Math.Sqrt(num6);
88 }
89 return num6;
90 }
91 return _nullValue;
92 }
93 case AggregateType.Min:
94 {
95 ushort num2 = ushort.MaxValue;
96 foreach (int num3 in records)
97 {
98 if (HasValue(num3))
99 {
101 flag = true;
102 }
103 }
104 if (flag)
105 {
106 return num2;
107 }
108 return _nullValue;
109 }
110 case AggregateType.Max:
111 {
112 ushort num15 = 0;
113 foreach (int num16 in records)
114 {
115 if (HasValue(num16))
116 {
118 flag = true;
119 }
120 }
121 if (flag)
122 {
123 return num15;
124 }
125 return _nullValue;
126 }
127 case AggregateType.First:
128 if (records.Length != 0)
129 {
130 return _values[records[0]];
131 }
132 return null;
133 case AggregateType.Count:
134 {
135 int num = 0;
136 for (int i = 0; i < records.Length; i++)
137 {
138 if (HasValue(records[i]))
139 {
140 num++;
141 }
142 }
143 return num;
144 }
145 }
146 }
147 catch (OverflowException)
148 {
149 throw ExprException.Overflow(typeof(ushort));
150 }
152 }
153
154 public override int Compare(int recordNo1, int recordNo2)
155 {
156 ushort num = _values[recordNo1];
157 ushort num2 = _values[recordNo2];
158 if (num == 0 || num2 == 0)
159 {
161 if (num3 != 0)
162 {
163 return num3;
164 }
165 }
166 return num - num2;
167 }
168
169 public override int CompareValueTo(int recordNo, object value)
170 {
171 if (_nullValue == value)
172 {
173 if (!HasValue(recordNo))
174 {
175 return 0;
176 }
177 return 1;
178 }
179 ushort num = _values[recordNo];
180 if (num == 0 && !HasValue(recordNo))
181 {
182 return -1;
183 }
184 return num.CompareTo((ushort)value);
185 }
186
187 public override object ConvertValue(object value)
188 {
189 if (_nullValue != value)
190 {
191 value = ((value == null) ? _nullValue : ((object)((IConvertible)value).ToUInt16(base.FormatProvider)));
192 }
193 return value;
194 }
195
196 public override void Copy(int recordNo1, int recordNo2)
197 {
200 }
201
202 public override object Get(int record)
203 {
204 ushort num = _values[record];
205 if (!num.Equals(0))
206 {
207 return num;
208 }
209 return GetBits(record);
210 }
211
212 public override void Set(int record, object value)
213 {
214 if (_nullValue == value)
215 {
216 _values[record] = 0;
217 SetNullBit(record, flag: true);
218 }
219 else
220 {
221 _values[record] = ((IConvertible)value).ToUInt16(base.FormatProvider);
222 SetNullBit(record, flag: false);
223 }
224 }
225
226 public override void SetCapacity(int capacity)
227 {
228 ushort[] array = new ushort[capacity];
229 if (_values != null)
230 {
232 }
233 _values = array;
234 base.SetCapacity(capacity);
235 }
236
237 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
238 public override object ConvertXmlToObject(string s)
239 {
240 return XmlConvert.ToUInt16(s);
241 }
242
243 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
244 public override string ConvertObjectToXml(object value)
245 {
246 return XmlConvert.ToString((ushort)value);
247 }
248
249 protected override object GetEmptyStorage(int recordCount)
250 {
251 return new ushort[recordCount];
252 }
253
254 protected override void CopyValue(int record, object store, BitArray nullbits, int storeIndex)
255 {
256 ushort[] array = (ushort[])store;
259 }
260
261 protected override void SetStorage(object store, BitArray nullbits)
262 {
263 _values = (ushort[])store;
265 }
266}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
void SetNullStorage(BitArray nullbits)
int CompareBits(int recordNo1, int recordNo2)
bool HasValue(int recordNo)
void SetNullBit(int recordNo, bool flag)
void CopyBits(int srcRecordNo, int dstRecordNo)
object GetBits(int recordNo)
override object ConvertValue(object value)
override string ConvertObjectToXml(object value)
override object Aggregate(int[] records, AggregateType kind)
override int Compare(int recordNo1, int recordNo2)
override void Copy(int recordNo1, int recordNo2)
override object ConvertXmlToObject(string s)
override void SetStorage(object store, BitArray nullbits)
override object GetEmptyStorage(int recordCount)
override void SetCapacity(int capacity)
override object Get(int record)
override int CompareValueTo(int recordNo, object value)
override void Set(int record, object value)
override void CopyValue(int record, object store, BitArray nullbits, int storeIndex)
static Exception AggregateException(AggregateType aggregateType, Type type)
static Exception Overflow(Type type)
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static double Sqrt(double d)
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static string ToString(bool value)
static ushort ToUInt16(string s)