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