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

◆ Aggregate()

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

Reimplemented from System.Data.Common.DataStorage.

Definition at line 16 of file Int32Storage.cs.

17 {
18 bool flag = false;
19 try
20 {
21 switch (kind)
22 {
23 case AggregateType.Sum:
24 {
25 long num4 = 0L;
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 int num14 = (int)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)_values[num10];
76 num9 += (double)_values[num10] * (double)_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 int num2 = int.MaxValue;
96 foreach (int num3 in records)
97 {
98 if (HasValue(num3))
99 {
100 num2 = Math.Min(_values[num3], num2);
101 flag = true;
102 }
103 }
104 if (flag)
105 {
106 return num2;
107 }
108 return _nullValue;
109 }
110 case AggregateType.Max:
111 {
112 int num15 = int.MinValue;
113 foreach (int num16 in records)
114 {
115 if (HasValue(num16))
116 {
117 num15 = Math.Max(_values[num16], num15);
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(int));
150 }
151 throw ExceptionBuilder.AggregateException(kind, _dataType);
152 }
bool HasValue(int recordNo)

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