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
+9
View File
@@ -68,7 +68,9 @@ public class DmxTests
var bars = gbm.Fetch(100, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
for (int i = 0; i < 50; i++)
{
dmx.Update(bars[i]);
}
var originalValue = dmx.Last;
@@ -114,7 +116,9 @@ public class DmxTests
var bars = gbm.Fetch(50, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
for (int i = 0; i < 30; i++)
{
dmx.Update(bars[i]);
}
var nanBar = new TBar(DateTime.UtcNow, double.NaN, double.NaN, double.NaN, double.NaN, 100);
var result = dmx.Update(nanBar);
@@ -130,7 +134,9 @@ public class DmxTests
var bars = gbm.Fetch(50, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
for (int i = 0; i < 30; i++)
{
dmx.Update(bars[i]);
}
var infBar = new TBar(DateTime.UtcNow, double.PositiveInfinity, double.PositiveInfinity, 0, 100, 100);
var result = dmx.Update(infBar);
@@ -151,7 +157,10 @@ public class DmxTests
// 2. Streaming Mode
var streamDmx = new Dmx(14);
for (int i = 0; i < bars.Count; i++)
{
streamDmx.Update(bars[i]);
}
double streamResult = streamDmx.Last.Value;
Assert.Equal(expected, streamResult, 9);
+19 -1
View File
@@ -109,10 +109,14 @@ public sealed class Dmx : ITValuePublisher
double downMove = _prevBar.Low - input.Low;
if (upMove > downMove && upMove > 0)
{
dmPlusRaw = upMove;
}
if (downMove > upMove && downMove > 0)
{
dmMinusRaw = downMove;
}
double tr1 = input.High - input.Low;
double tr2 = Math.Abs(input.High - _prevBar.Close);
@@ -147,7 +151,9 @@ public sealed class Dmx : ITValuePublisher
{
int count = source.Count;
if (count == 0)
{
return [];
}
var t = new List<long>(count);
var v = new List<double>(count);
@@ -182,13 +188,19 @@ public sealed class Dmx : ITValuePublisher
{
int len = high.Length;
if (len == 0)
{
return;
}
if (low.Length != len || close.Length != len || destination.Length != len)
{
throw new ArgumentException("All input spans must have the same length", nameof(destination));
}
if (period <= 0)
{
throw new ArgumentException("Period must be greater than zero.", nameof(period));
}
// Use single ArrayPool rent with slicing for better cache locality and fewer allocations
// Need 6 buffers of len each: dmPlus, dmMinus, tr, dmPlusSmooth, dmMinusSmooth, trSmooth
@@ -238,10 +250,14 @@ public sealed class Dmx : ITValuePublisher
double dmMinusRaw = 0.0;
if (upMove > downMove && upMove > 0.0)
{
dmPlusRaw = upMove;
}
if (downMove > upMove && downMove > 0.0)
{
dmMinusRaw = downMove;
}
double tr1 = h - l;
double tr2 = Math.Abs(h - pc);
@@ -275,7 +291,9 @@ public sealed class Dmx : ITValuePublisher
finally
{
if (rented != null)
{
ArrayPool<double>.Shared.Return(rented);
}
}
}
@@ -284,4 +302,4 @@ public sealed class Dmx : ITValuePublisher
var dmx = new Dmx(period);
return dmx.Update(source);
}
}
}