feat: Refactor TBar and TValue to record structs; improve readability and performance

fix: Update condition checks in Htit and Mgdi for better numerical stability
refactor: Simplify parameter struct in T3 and enhance Vidya state management
This commit is contained in:
Miha Kralj
2025-12-17 07:27:45 -08:00
parent d277e08056
commit 8cec2fec8d
6 changed files with 20 additions and 100 deletions
+3 -22
View File
@@ -7,25 +7,14 @@ namespace QuanTAlib;
/// Pure data type: 16 bytes (long + double).
/// </summary>
[SkipLocalsInit]
public readonly struct TValue : IEquatable<TValue>
public readonly record struct TValue(long Time, double Value)
{
public readonly long Time;
public readonly double Value;
public DateTime AsDateTime => new(Time, DateTimeKind.Utc);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TValue(long time, double value)
public TValue(DateTime time, double value)
: this(time.Kind == DateTimeKind.Utc ? time.Ticks : time.ToUniversalTime().Ticks, value)
{
Time = time;
Value = value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TValue(DateTime time, double value)
{
Time = time.Kind == DateTimeKind.Utc ? time.Ticks : time.ToUniversalTime().Ticks;
Value = value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -36,12 +25,4 @@ public readonly struct TValue : IEquatable<TValue>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => $"[{AsDateTime:yyyy-MM-dd HH:mm:ss}, {Value:F2}]";
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(TValue other) => Time == other.Time && Value == other.Value;
public override bool Equals(object? obj) => obj is TValue other && Equals(other);
public override int GetHashCode() => HashCode.Combine(Time, Value);
public static bool operator ==(TValue left, TValue right) => left.Equals(right);
public static bool operator !=(TValue left, TValue right) => !left.Equals(right);
}