Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Aggregate()

override object System.Data.Common.ByteStorage.Aggregate ( int[] records,
AggregateType kind )
inlinevirtual

Reimplemented from System.Data.Common.DataStorage.

Definition at line 16 of file ByteStorage.cs.

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 }
141 throw ExceptionBuilder.AggregateException(kind, _dataType);
142 }

References System.Data.Common.DataStorage._dataType, System.Data.Common.DataStorage._nullValue, System.Data.Common.ByteStorage._values, System.Data.ExceptionBuilder.AggregateException(), System.Xml.Dictionary, System.E, System.Data.IsNull, System.L, System.Math.Max(), System.Math.Min(), System.Data.ExprException.Overflow(), and System.Math.Sqrt().