style patterns

This commit is contained in:
Miha Kralj
2026-01-25 16:01:45 -08:00
parent 2836f253c4
commit e59665c8f0
399 changed files with 6892 additions and 1323 deletions
@@ -164,4 +164,4 @@ public class HammaIndicatorTests
Assert.Equal(20, indicator.Period);
Assert.Equal(0, HammaIndicator.MinHistoryDepths);
}
}
}
+1 -1
View File
@@ -55,4 +55,4 @@ public class HammaIndicator : Indicator, IWatchlistIndicator
Series.SetValue(result.Value, ma.IsHot, ShowColdValues);
}
}
}
+1 -1
View File
@@ -409,4 +409,4 @@ public class HammaTests
Assert.Equal(i * 10.0, result.Value, 1e-9);
}
}
}
}
@@ -203,4 +203,4 @@ public sealed class HammaValidationTests : IDisposable
// All edge weights should be equal
Assert.Equal(w0, w4, 1e-10);
}
}
}
+24 -4
View File
@@ -62,7 +62,9 @@ public sealed class Hamma : AbstractBase
public Hamma(int period = 10)
{
if (period <= 0)
{
throw new ArgumentException("Period must be greater than 0", nameof(period));
}
_period = period;
_buffer = new RingBuffer(period);
@@ -184,7 +186,10 @@ public sealed class Hamma : AbstractBase
public override TSeries Update(TSeries source)
{
if (source.Count == 0) return new TSeries([], []);
if (source.Count == 0)
{
return new TSeries([], []);
}
int len = source.Count;
var t = new List<long>(len);
@@ -224,7 +229,10 @@ public sealed class Hamma : AbstractBase
private double CalculateWeightedSum()
{
int count = _buffer.Count;
if (count == 0) return 0;
if (count == 0)
{
return 0;
}
if (count < _period)
{
@@ -283,9 +291,14 @@ public sealed class Hamma : AbstractBase
public static void Calculate(ReadOnlySpan<double> source, Span<double> output, int period = 10)
{
if (period <= 0)
{
throw new ArgumentException("Period must be greater than 0", nameof(period));
}
if (source.Length != output.Length)
{
throw new ArgumentException("Source and output must have the same length", nameof(output));
}
// Allocation Strategy: Stack for small periods, Pool for large
double[]? weightsArray = period > 256 ? ArrayPool<double>.Shared.Rent(period) : null;
@@ -381,8 +394,15 @@ public sealed class Hamma : AbstractBase
}
finally
{
if (weightsArray != null) ArrayPool<double>.Shared.Return(weightsArray);
if (bufferArray != null) ArrayPool<double>.Shared.Return(bufferArray);
if (weightsArray != null)
{
ArrayPool<double>.Shared.Return(weightsArray);
}
if (bufferArray != null)
{
ArrayPool<double>.Shared.Return(bufferArray);
}
}
}