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
+4 -1
View File
@@ -43,7 +43,10 @@ public class HighestIndicator : Indicator, IWatchlistIndicator
protected override void OnUpdate(UpdateArgs args)
{
if (_highest == null || _selector == null) return;
if (_highest == null || _selector == null)
{
return;
}
var item = HistoricalData[0, SeekOriginHistory.End];
double value = _selector(item);
+1 -1
View File
@@ -297,4 +297,4 @@ public class HighestTests
indicator.Update(new TValue(time.AddMinutes(5), 5.0));
Assert.Equal(9.0, indicator.Last.Value, Tolerance);
}
}
}
+34 -3
View File
@@ -33,7 +33,9 @@ public sealed class Highest : AbstractBase
public Highest(int period)
{
if (period < 1)
{
throw new ArgumentException("Period must be >= 1", nameof(period));
}
_period = period;
_buffer = new RingBuffer(period);
@@ -58,9 +60,13 @@ public sealed class Highest : AbstractBase
public override TValue Update(TValue input, bool isNew = true)
{
if (isNew)
{
_p_state = _state;
}
else
{
_state = _p_state;
}
double value = double.IsFinite(input.Value) ? input.Value : _state.LastValid;
_state = new State(value);
@@ -112,11 +118,19 @@ public sealed class Highest : AbstractBase
public static void Calculate(ReadOnlySpan<double> source, Span<double> output, int period)
{
if (source.Length == 0)
{
throw new ArgumentException("Source cannot be empty", nameof(source));
}
if (output.Length < source.Length)
{
throw new ArgumentException("Output length must be >= source length", nameof(output));
}
if (period < 1)
{
throw new ArgumentException("Period must be >= 1", nameof(period));
}
int len = source.Length;
@@ -169,7 +183,11 @@ public sealed class Highest : AbstractBase
while (count > 0 && deque[head] <= i - period)
{
head++;
if (head >= capacity) head -= capacity;
if (head >= capacity)
{
head -= capacity;
}
count--;
}
@@ -177,7 +195,11 @@ public sealed class Highest : AbstractBase
while (count > 0)
{
int backIdx = tail - 1;
if (backIdx < 0) backIdx += capacity;
if (backIdx < 0)
{
backIdx += capacity;
}
if (values[deque[backIdx]] <= value)
{
tail = backIdx;
@@ -192,7 +214,11 @@ public sealed class Highest : AbstractBase
// Add current index at tail
deque[tail] = i;
tail++;
if (tail >= capacity) tail -= capacity;
if (tail >= capacity)
{
tail -= capacity;
}
count++;
output[i] = values[deque[head]];
@@ -201,9 +227,14 @@ public sealed class Highest : AbstractBase
finally
{
if (rentedDeque != null)
{
System.Buffers.ArrayPool<int>.Shared.Return(rentedDeque);
}
if (rentedValues != null)
{
System.Buffers.ArrayPool<double>.Shared.Return(rentedValues);
}
}
}