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