초기커밋

This commit is contained in:
2025-05-01 07:20:41 +09:00
commit 98bb2e3c5c
2747 changed files with 646947 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using ServerCore; using ServerBase;
namespace ServerBase;
public class EntityAggregator<TKey, TCounterType>
where TKey : ITuple
where TCounterType : struct
{
private readonly ConcurrentDictionary<TKey, TCounterType> m_counters = new();
public EntityAggregator()
{
}
public void reset()
{
m_counters.Clear();
}
public void incCounter(TKey key, TCounterType toIncValue, Func<TCounterType, TCounterType, TCounterType> fnUpdate)
{
var add_counter = delegate (TKey key)
{
return toIncValue;
};
var update_recorder = delegate (TKey key, TCounterType currValue)
{
return fnUpdate(currValue, toIncValue);
};
m_counters.AddOrUpdate(key, add_counter, update_recorder);
}
public void decCounter(TKey key, TCounterType toDecValue, Func<TCounterType, TCounterType, TCounterType> fnUpdate)
{
var add_counter = delegate (TKey key)
{
return toDecValue;
};
var update_recorder = delegate (TKey key, TCounterType currValue)
{
return fnUpdate(currValue, toDecValue);
};
m_counters.AddOrUpdate(key, add_counter, update_recorder);
}
public TCounterType getCounter(TKey key, TCounterType defaultValue)
{
if(false == m_counters.TryGetValue(key, out var found_counter))
{
return defaultValue;
}
return found_counter;
}
public ConcurrentDictionary<TKey, TCounterType> getCounters() => m_counters;
}