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

◆ Aggregate()

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

Reimplemented from System.Data.Common.DataStorage.

Definition at line 16 of file Int64Storage.cs.

17 {
18 bool flag = false;
19 try
20 {
21 switch (kind)
22 {
23 case AggregateType.Sum:
24 {
25 long num15 = 0L;
26 foreach (int num16 in records)
27 {
28 if (HasValue(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 decimal num7 = default(decimal);
43 int num8 = 0;
44 foreach (int num9 in records)
45 {
46 if (HasValue(num9))
47 {
48 num7 += (decimal)_values[num9];
49 num8++;
50 flag = true;
51 }
52 }
53 if (flag)
54 {
55 long num10 = (long)(num7 / (decimal)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 (HasValue(num6))
71 {
72 num4 += (double)_values[num6];
73 num5 += (double)_values[num6] * (double)_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 long num13 = long.MaxValue;
93 foreach (int num14 in records)
94 {
95 if (HasValue(num14))
96 {
97 num13 = Math.Min(_values[num14], num13);
98 flag = true;
99 }
100 }
101 if (flag)
102 {
103 return num13;
104 }
105 return _nullValue;
106 }
107 case AggregateType.Max:
108 {
109 long num11 = long.MinValue;
110 foreach (int num12 in records)
111 {
112 if (HasValue(num12))
113 {
114 num11 = Math.Max(_values[num12], num11);
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(long));
137 }
138 throw ExceptionBuilder.AggregateException(kind, _dataType);
139 }
bool HasValue(int recordNo)

References System.Data.Common.DataStorage._dataType, System.Data.Common.DataStorage._nullValue, System.Data.Common.Int64Storage._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().