feat: Implement IEquatable for state structures in Dema, Ema, T3, Tema, and Hma classes; update IsHot logic in Hma

This commit is contained in:
Miha Kralj
2025-12-07 18:12:24 -08:00
parent 3975ff2d7f
commit 2a554963d8
6 changed files with 83 additions and 10 deletions
+15 -1
View File
@@ -26,7 +26,7 @@ namespace QuanTAlib;
[SkipLocalsInit]
public sealed class Tema : ITValuePublisher
{
private struct EmaState
private struct EmaState : IEquatable<EmaState>
{
public double Ema;
public double E;
@@ -34,6 +34,20 @@ public sealed class Tema : ITValuePublisher
public bool IsCompensated;
public static EmaState New() => new() { Ema = 0, E = 1.0, IsHot = false, IsCompensated = false };
public override bool Equals(object? obj) => obj is EmaState other && Equals(other);
public bool Equals(EmaState other) =>
Ema == other.Ema &&
E == other.E &&
IsHot == other.IsHot &&
IsCompensated == other.IsCompensated;
public override int GetHashCode() => HashCode.Combine(Ema, E, IsHot, IsCompensated);
public static bool operator ==(EmaState left, EmaState right) => left.Equals(right);
public static bool operator !=(EmaState left, EmaState right) => !left.Equals(right);
}
private readonly double _alpha;