++
This commit is contained in:
@@ -400,8 +400,8 @@ public static partial class CollectionsMinusExtensions
|
||||
if (units is null) return null!;
|
||||
int count = units.Count;
|
||||
if (count == 0) return [];
|
||||
if (units is T[] array) return array.Multiply(subtrahend);
|
||||
if (units is List<T> list) return list.Multiply(subtrahend);
|
||||
if (units is T[] array) return array.Minus(subtrahend);
|
||||
if (units is List<T> list) return list.Minus(subtrahend);
|
||||
|
||||
T[] sharedArray = ArrayPool<T>.Shared.Rent(count);
|
||||
var finalResult = new T[count];
|
||||
@@ -423,8 +423,8 @@ public static partial class CollectionsMinusExtensions
|
||||
if (units is null) return null!;
|
||||
int count = units.Count;
|
||||
if (count == 0) return [];
|
||||
if (units is T?[] array) return array.Multiply(subtrahend);
|
||||
if (units is List<T?> list) return list.Multiply(subtrahend);
|
||||
if (units is T?[] array) return array.Minus(subtrahend);
|
||||
if (units is List<T?> list) return list.Minus(subtrahend);
|
||||
|
||||
T?[] sharedNullableArray = ArrayPool<T?>.Shared.Rent(count);
|
||||
var resultArray = new T?[count];
|
||||
@@ -454,8 +454,8 @@ public static partial class CollectionsMinusExtensions
|
||||
if (units is null) return null!;
|
||||
int count = units.Count;
|
||||
if (count == 0) return [];
|
||||
if (units is T[] array) return array.Multiply(minuend);
|
||||
if (units is List<T> list) return list.Multiply(minuend);
|
||||
if (units is T[] array) return array.Minus(minuend);
|
||||
if (units is List<T> list) return list.Minus(minuend);
|
||||
|
||||
T[] sharedArray = ArrayPool<T>.Shared.Rent(count);
|
||||
var finalResult = new T[count];
|
||||
@@ -477,8 +477,8 @@ public static partial class CollectionsMinusExtensions
|
||||
if (units is null) return null!;
|
||||
int count = units.Count;
|
||||
if (count == 0) return [];
|
||||
if (units is T?[] array) return array.Multiply(minuend);
|
||||
if (units is List<T?> list) return list.Multiply(minuend);
|
||||
if (units is T?[] array) return array.Minus(minuend);
|
||||
if (units is List<T?> list) return list.Minus(minuend);
|
||||
|
||||
T?[] sharedNullableArray = ArrayPool<T?>.Shared.Rent(count);
|
||||
var resultArray = new T?[count];
|
||||
|
||||
@@ -211,83 +211,77 @@ public static partial class CollectionsPowExtensions
|
||||
}
|
||||
|
||||
// === ICollection<Length> ===
|
||||
internal static ICollection<R> Pow<T, R>(this ICollection<T> units, int power)
|
||||
internal static void Pow<T, R>(this ICollection<T> units, int power, Span<R> destination)
|
||||
where T : struct, IMensuraUnit, IEquatable<T>
|
||||
where R : struct, IMensuraUnit, IEquatable<R>
|
||||
{
|
||||
if (units is null) return null!;
|
||||
if (units is T[] array) return array.Pow<T, R>(power);
|
||||
if (units is List<T> list) return list.Pow<T, R>(power);
|
||||
if (units is null) return;
|
||||
int count = units.Count;
|
||||
if (count == 0) return;
|
||||
if (destination.Length < count)
|
||||
throw new ArgumentException("Destination too short");
|
||||
|
||||
ICollection<R> result = [];
|
||||
if (units is T[] array) { array.AsSpan().Pow(power, destination); return; }
|
||||
if (units is List<T> list) { CollectionsMarshal.AsSpan(list).Pow(power, destination); return; }
|
||||
|
||||
int i = 0;
|
||||
foreach (var item in units)
|
||||
result.Add(item.ToDouble().QuickPow(power).ToUnit<R>());
|
||||
return result;
|
||||
destination[i++] = item.ToDouble().QuickPow(power).ToUnit<R>();
|
||||
}
|
||||
internal static ICollection<R?> Pow<T, R>(this ICollection<T?> units, int power)
|
||||
internal static void Pow<T, R>(this ICollection<T?> units, int power, Span<R?> destination)
|
||||
where T : struct, IMensuraUnit, IEquatable<T>
|
||||
where R : struct, IMensuraUnit, IEquatable<R>
|
||||
{
|
||||
if (units is null) return null!;
|
||||
if (units is T?[] array) return array.Pow<T, R>(power);
|
||||
if (units is List<T?> list) return list.Pow<T, R>(power);
|
||||
if (units is null) return;
|
||||
int count = units.Count;
|
||||
if (count == 0) return;
|
||||
if (destination.Length < count)
|
||||
throw new ArgumentException("Destination too short");
|
||||
|
||||
ICollection<R?> result = [];
|
||||
if (units is T?[] array) { array.AsSpan().Pow(power, destination); return; }
|
||||
if (units is List<T?> list) { CollectionsMarshal.AsSpan(list).Pow(power, destination); return; }
|
||||
|
||||
int i = 0;
|
||||
foreach (var item in units)
|
||||
result.Add((item.HasValue ? item.Value.ToDouble().QuickPow(power) : 0d).ToUnit<R>());
|
||||
return result;
|
||||
destination[i++] = item.HasValue
|
||||
? item.Value.ToDouble().QuickPow(power).ToUnit<R>() : null;
|
||||
}
|
||||
|
||||
// === IReadOnlyCollection<Length> ===
|
||||
internal static IReadOnlyCollection<R> Pow<T, R>(this IReadOnlyCollection<T> units, int power)
|
||||
internal static void Pow<T, R>(this IReadOnlyCollection<T> units, int power, Span<R> destination)
|
||||
where T : struct, IMensuraUnit, IEquatable<T>
|
||||
where R : struct, IMensuraUnit, IEquatable<R>
|
||||
{
|
||||
if (units is null) return null!;
|
||||
if (units is null) return;
|
||||
int count = units.Count;
|
||||
if (count == 0) return [];
|
||||
if (units is T[] array) return array.Pow<T, R>(power);
|
||||
if (units is List<T> list) return list.Pow<T, R>(power);
|
||||
if (count == 0) return;
|
||||
if (destination.Length < count)
|
||||
throw new ArgumentException("Destination too short");
|
||||
|
||||
T[] sharedArray = ArrayPool<T>.Shared.Rent(count);
|
||||
var finalResult = new R[count];
|
||||
if (units is T[] array) { array.AsSpan().Pow(power, destination); return; }
|
||||
if (units is List<T> list) { CollectionsMarshal.AsSpan(list).Pow(power, destination); return; }
|
||||
|
||||
try
|
||||
{
|
||||
int index = 0;
|
||||
foreach (var item in units) sharedArray[index++] = item;
|
||||
Pow(sharedArray, power, finalResult);
|
||||
return finalResult;
|
||||
}
|
||||
finally
|
||||
{
|
||||
ArrayPool<T>.Shared.Return(sharedArray);
|
||||
}
|
||||
int i = 0;
|
||||
foreach (var item in units)
|
||||
destination[i++] = item.ToDouble().QuickPow(power).ToUnit<R>();
|
||||
}
|
||||
internal static IReadOnlyCollection<R?> Pow<T, R>(this IReadOnlyCollection<T?> units, int power)
|
||||
internal static void Pow<T, R>(this IReadOnlyCollection<T?> units, int power, Span<R?> destination)
|
||||
where T : struct, IMensuraUnit, IEquatable<T>
|
||||
where R : struct, IMensuraUnit, IEquatable<R>
|
||||
{
|
||||
if (units is null) return null!;
|
||||
if (units is null) return;
|
||||
int count = units.Count;
|
||||
if (count == 0) return [];
|
||||
if (units is T?[] array) return array.Pow<T, R>(power);
|
||||
if (units is List<T?> list) return list.Pow<T, R>(power);
|
||||
if (count == 0) return;
|
||||
if (destination.Length < count)
|
||||
throw new ArgumentException("Destination too short");
|
||||
|
||||
T?[] sharedArray = ArrayPool<T?>.Shared.Rent(count);
|
||||
var finalResult = new R?[count];
|
||||
if (units is T?[] array) { array.AsSpan().Pow(power, destination); return; }
|
||||
if (units is List<T?> list) { CollectionsMarshal.AsSpan(list).Pow(power, destination); return; }
|
||||
|
||||
try
|
||||
{
|
||||
int index = 0;
|
||||
foreach (var item in units) sharedArray[index++] = item;
|
||||
Pow(sharedArray, power, finalResult);
|
||||
return finalResult;
|
||||
}
|
||||
finally
|
||||
{
|
||||
ArrayPool<T?>.Shared.Return(sharedArray);
|
||||
}
|
||||
int i = 0;
|
||||
foreach (var item in units)
|
||||
destination[i++] = item.HasValue
|
||||
? item.Value.ToDouble().QuickPow(power).ToUnit<R>() : null;
|
||||
}
|
||||
|
||||
// === IEnumerable<T, R> + yeild ===
|
||||
|
||||
Reference in New Issue
Block a user