|
| 1 | + |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | + |
| 5 | +// ReSharper disable once CheckNamespace |
| 6 | +namespace StructLinq |
| 7 | +{ |
| 8 | + public static partial class StructEnumerable |
| 9 | + { |
| 10 | + #region private fields |
| 11 | + private static Int16 Int16Max<TEnumerator>(TEnumerator enumerator) |
| 12 | + where TEnumerator : IEnumerator<Int16> |
| 13 | + { |
| 14 | + if (!enumerator.MoveNext()) |
| 15 | + throw new ArgumentOutOfRangeException("No elements"); |
| 16 | + Int16 result = enumerator.Current; |
| 17 | + while (enumerator.MoveNext()) |
| 18 | + { |
| 19 | + var current = enumerator.Current; |
| 20 | + if (current > result) |
| 21 | + result = current; |
| 22 | + } |
| 23 | + return result; |
| 24 | + } |
| 25 | + #endregion |
| 26 | + public static Int16 Max<TEnumerator>(this ITypedEnumerable<Int16, TEnumerator> enumerable) |
| 27 | + where TEnumerator : IEnumerator<Int16> |
| 28 | + { |
| 29 | + using (var enumerator = enumerable.GetTypedEnumerator()) |
| 30 | + { |
| 31 | + return Int16Max(enumerator); |
| 32 | + } |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + |
| 37 | + public static partial class StructEnumerable |
| 38 | + { |
| 39 | + #region private fields |
| 40 | + private static Int32 Int32Max<TEnumerator>(TEnumerator enumerator) |
| 41 | + where TEnumerator : IEnumerator<Int32> |
| 42 | + { |
| 43 | + if (!enumerator.MoveNext()) |
| 44 | + throw new ArgumentOutOfRangeException("No elements"); |
| 45 | + Int32 result = enumerator.Current; |
| 46 | + while (enumerator.MoveNext()) |
| 47 | + { |
| 48 | + var current = enumerator.Current; |
| 49 | + if (current > result) |
| 50 | + result = current; |
| 51 | + } |
| 52 | + return result; |
| 53 | + } |
| 54 | + #endregion |
| 55 | + public static Int32 Max<TEnumerator>(this ITypedEnumerable<Int32, TEnumerator> enumerable) |
| 56 | + where TEnumerator : IEnumerator<Int32> |
| 57 | + { |
| 58 | + using (var enumerator = enumerable.GetTypedEnumerator()) |
| 59 | + { |
| 60 | + return Int32Max(enumerator); |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + |
| 66 | + public static partial class StructEnumerable |
| 67 | + { |
| 68 | + #region private fields |
| 69 | + private static Int64 Int64Max<TEnumerator>(TEnumerator enumerator) |
| 70 | + where TEnumerator : IEnumerator<Int64> |
| 71 | + { |
| 72 | + if (!enumerator.MoveNext()) |
| 73 | + throw new ArgumentOutOfRangeException("No elements"); |
| 74 | + Int64 result = enumerator.Current; |
| 75 | + while (enumerator.MoveNext()) |
| 76 | + { |
| 77 | + var current = enumerator.Current; |
| 78 | + if (current > result) |
| 79 | + result = current; |
| 80 | + } |
| 81 | + return result; |
| 82 | + } |
| 83 | + #endregion |
| 84 | + public static Int64 Max<TEnumerator>(this ITypedEnumerable<Int64, TEnumerator> enumerable) |
| 85 | + where TEnumerator : IEnumerator<Int64> |
| 86 | + { |
| 87 | + using (var enumerator = enumerable.GetTypedEnumerator()) |
| 88 | + { |
| 89 | + return Int64Max(enumerator); |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | + public static partial class StructEnumerable |
| 96 | + { |
| 97 | + #region private fields |
| 98 | + private static UInt16 UInt16Max<TEnumerator>(TEnumerator enumerator) |
| 99 | + where TEnumerator : IEnumerator<UInt16> |
| 100 | + { |
| 101 | + if (!enumerator.MoveNext()) |
| 102 | + throw new ArgumentOutOfRangeException("No elements"); |
| 103 | + UInt16 result = enumerator.Current; |
| 104 | + while (enumerator.MoveNext()) |
| 105 | + { |
| 106 | + var current = enumerator.Current; |
| 107 | + if (current > result) |
| 108 | + result = current; |
| 109 | + } |
| 110 | + return result; |
| 111 | + } |
| 112 | + #endregion |
| 113 | + public static UInt16 Max<TEnumerator>(this ITypedEnumerable<UInt16, TEnumerator> enumerable) |
| 114 | + where TEnumerator : IEnumerator<UInt16> |
| 115 | + { |
| 116 | + using (var enumerator = enumerable.GetTypedEnumerator()) |
| 117 | + { |
| 118 | + return UInt16Max(enumerator); |
| 119 | + } |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + |
| 124 | + public static partial class StructEnumerable |
| 125 | + { |
| 126 | + #region private fields |
| 127 | + private static UInt32 UInt32Max<TEnumerator>(TEnumerator enumerator) |
| 128 | + where TEnumerator : IEnumerator<UInt32> |
| 129 | + { |
| 130 | + if (!enumerator.MoveNext()) |
| 131 | + throw new ArgumentOutOfRangeException("No elements"); |
| 132 | + UInt32 result = enumerator.Current; |
| 133 | + while (enumerator.MoveNext()) |
| 134 | + { |
| 135 | + var current = enumerator.Current; |
| 136 | + if (current > result) |
| 137 | + result = current; |
| 138 | + } |
| 139 | + return result; |
| 140 | + } |
| 141 | + #endregion |
| 142 | + public static UInt32 Max<TEnumerator>(this ITypedEnumerable<UInt32, TEnumerator> enumerable) |
| 143 | + where TEnumerator : IEnumerator<UInt32> |
| 144 | + { |
| 145 | + using (var enumerator = enumerable.GetTypedEnumerator()) |
| 146 | + { |
| 147 | + return UInt32Max(enumerator); |
| 148 | + } |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + |
| 153 | + public static partial class StructEnumerable |
| 154 | + { |
| 155 | + #region private fields |
| 156 | + private static UInt64 UInt64Max<TEnumerator>(TEnumerator enumerator) |
| 157 | + where TEnumerator : IEnumerator<UInt64> |
| 158 | + { |
| 159 | + if (!enumerator.MoveNext()) |
| 160 | + throw new ArgumentOutOfRangeException("No elements"); |
| 161 | + UInt64 result = enumerator.Current; |
| 162 | + while (enumerator.MoveNext()) |
| 163 | + { |
| 164 | + var current = enumerator.Current; |
| 165 | + if (current > result) |
| 166 | + result = current; |
| 167 | + } |
| 168 | + return result; |
| 169 | + } |
| 170 | + #endregion |
| 171 | + public static UInt64 Max<TEnumerator>(this ITypedEnumerable<UInt64, TEnumerator> enumerable) |
| 172 | + where TEnumerator : IEnumerator<UInt64> |
| 173 | + { |
| 174 | + using (var enumerator = enumerable.GetTypedEnumerator()) |
| 175 | + { |
| 176 | + return UInt64Max(enumerator); |
| 177 | + } |
| 178 | + } |
| 179 | + } |
| 180 | + |
| 181 | + |
| 182 | + public static partial class StructEnumerable |
| 183 | + { |
| 184 | + #region private fields |
| 185 | + private static Single SingleMax<TEnumerator>(TEnumerator enumerator) |
| 186 | + where TEnumerator : IEnumerator<Single> |
| 187 | + { |
| 188 | + if (!enumerator.MoveNext()) |
| 189 | + throw new ArgumentOutOfRangeException("No elements"); |
| 190 | + Single result = enumerator.Current; |
| 191 | + while (enumerator.MoveNext()) |
| 192 | + { |
| 193 | + var current = enumerator.Current; |
| 194 | + if (current > result) |
| 195 | + result = current; |
| 196 | + } |
| 197 | + return result; |
| 198 | + } |
| 199 | + #endregion |
| 200 | + public static Single Max<TEnumerator>(this ITypedEnumerable<Single, TEnumerator> enumerable) |
| 201 | + where TEnumerator : IEnumerator<Single> |
| 202 | + { |
| 203 | + using (var enumerator = enumerable.GetTypedEnumerator()) |
| 204 | + { |
| 205 | + return SingleMax(enumerator); |
| 206 | + } |
| 207 | + } |
| 208 | + } |
| 209 | + |
| 210 | + |
| 211 | + public static partial class StructEnumerable |
| 212 | + { |
| 213 | + #region private fields |
| 214 | + private static Double DoubleMax<TEnumerator>(TEnumerator enumerator) |
| 215 | + where TEnumerator : IEnumerator<Double> |
| 216 | + { |
| 217 | + if (!enumerator.MoveNext()) |
| 218 | + throw new ArgumentOutOfRangeException("No elements"); |
| 219 | + Double result = enumerator.Current; |
| 220 | + while (enumerator.MoveNext()) |
| 221 | + { |
| 222 | + var current = enumerator.Current; |
| 223 | + if (current > result) |
| 224 | + result = current; |
| 225 | + } |
| 226 | + return result; |
| 227 | + } |
| 228 | + #endregion |
| 229 | + public static Double Max<TEnumerator>(this ITypedEnumerable<Double, TEnumerator> enumerable) |
| 230 | + where TEnumerator : IEnumerator<Double> |
| 231 | + { |
| 232 | + using (var enumerator = enumerable.GetTypedEnumerator()) |
| 233 | + { |
| 234 | + return DoubleMax(enumerator); |
| 235 | + } |
| 236 | + } |
| 237 | + } |
| 238 | + |
| 239 | + |
| 240 | + public static partial class StructEnumerable |
| 241 | + { |
| 242 | + #region private fields |
| 243 | + private static Byte ByteMax<TEnumerator>(TEnumerator enumerator) |
| 244 | + where TEnumerator : IEnumerator<Byte> |
| 245 | + { |
| 246 | + if (!enumerator.MoveNext()) |
| 247 | + throw new ArgumentOutOfRangeException("No elements"); |
| 248 | + Byte result = enumerator.Current; |
| 249 | + while (enumerator.MoveNext()) |
| 250 | + { |
| 251 | + var current = enumerator.Current; |
| 252 | + if (current > result) |
| 253 | + result = current; |
| 254 | + } |
| 255 | + return result; |
| 256 | + } |
| 257 | + #endregion |
| 258 | + public static Byte Max<TEnumerator>(this ITypedEnumerable<Byte, TEnumerator> enumerable) |
| 259 | + where TEnumerator : IEnumerator<Byte> |
| 260 | + { |
| 261 | + using (var enumerator = enumerable.GetTypedEnumerator()) |
| 262 | + { |
| 263 | + return ByteMax(enumerator); |
| 264 | + } |
| 265 | + } |
| 266 | + } |
| 267 | + |
| 268 | + |
| 269 | + public static partial class StructEnumerable |
| 270 | + { |
| 271 | + #region private fields |
| 272 | + private static SByte SByteMax<TEnumerator>(TEnumerator enumerator) |
| 273 | + where TEnumerator : IEnumerator<SByte> |
| 274 | + { |
| 275 | + if (!enumerator.MoveNext()) |
| 276 | + throw new ArgumentOutOfRangeException("No elements"); |
| 277 | + SByte result = enumerator.Current; |
| 278 | + while (enumerator.MoveNext()) |
| 279 | + { |
| 280 | + var current = enumerator.Current; |
| 281 | + if (current > result) |
| 282 | + result = current; |
| 283 | + } |
| 284 | + return result; |
| 285 | + } |
| 286 | + #endregion |
| 287 | + public static SByte Max<TEnumerator>(this ITypedEnumerable<SByte, TEnumerator> enumerable) |
| 288 | + where TEnumerator : IEnumerator<SByte> |
| 289 | + { |
| 290 | + using (var enumerator = enumerable.GetTypedEnumerator()) |
| 291 | + { |
| 292 | + return SByteMax(enumerator); |
| 293 | + } |
| 294 | + } |
| 295 | + } |
| 296 | + |
| 297 | + |
| 298 | +} |
0 commit comments