mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-15 17:18:05 +00:00
feat(tests): enhance tests with GBM for noise generation and improve tolerance for MAMA validation
feat(trends): implement IDisposable in Bessel and Conv classes to manage event subscriptions fix(trends): add validation for period and parameters in Kama and MGDI calculations fix(trends): clamp logarithmic calculations in JMA to avoid -Infinity
This commit is contained in:
@@ -28,6 +28,12 @@ public sealed class RingBuffer : IEnumerable<double>
|
||||
private int _count;
|
||||
private double _sum;
|
||||
|
||||
// Snapshot state
|
||||
private int _savedHead;
|
||||
private int _savedCount;
|
||||
private double _savedSum;
|
||||
private double _savedValue;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new RingBuffer with the specified capacity.
|
||||
/// Uses pinned memory for SIMD compatibility.
|
||||
@@ -435,6 +441,31 @@ public sealed class RingBuffer : IEnumerable<double>
|
||||
_sum = source._sum;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Captures the current state of the buffer.
|
||||
/// Must be called BEFORE adding a new value if you intend to Restore later.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Snapshot()
|
||||
{
|
||||
_savedHead = _head;
|
||||
_savedCount = _count;
|
||||
_savedSum = _sum;
|
||||
_savedValue = _buffer[_head];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restores the buffer to the state captured by Snapshot.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Restore()
|
||||
{
|
||||
_head = _savedHead;
|
||||
_count = _savedCount;
|
||||
_sum = _savedSum;
|
||||
_buffer[_head] = _savedValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates through the buffer in chronological order.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user