add performance logging on demand, fix minion issues

This commit is contained in:
rootdarkarchon
2023-02-19 16:11:40 +01:00
parent 6cf0ecdef1
commit 44450b24b4
29 changed files with 580 additions and 294 deletions

View File

@@ -0,0 +1,46 @@
using System.Collections;
namespace MareSynchronos.Utils;
public class RollingList<T> : IEnumerable<T>
{
private readonly LinkedList<T> _list = new();
private readonly object _addLock = new();
public RollingList(int maximumCount)
{
if (maximumCount <= 0)
throw new ArgumentException(message: null, nameof(maximumCount));
MaximumCount = maximumCount;
}
public int MaximumCount { get; }
public int Count => _list.Count;
public void Add(T value)
{
lock (_addLock)
{
if (_list.Count == MaximumCount)
{
_list.RemoveFirst();
}
_list.AddLast(value);
}
}
public T this[int index]
{
get
{
if (index < 0 || index >= Count)
throw new ArgumentOutOfRangeException(nameof(index));
return _list.Skip(index).First();
}
}
public IEnumerator<T> GetEnumerator() => _list.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}