namespace XFENewsApplication.Utilities; public class HistoryManager(int capacity = 100) where T : notnull { private readonly LinkedList _historyList = new(); private readonly Dictionary _historyMap = []; public void Visit(T visitValue, R content) { if (_historyMap.ContainsKey(visitValue)) { _historyList.Remove(visitValue); } else if (_historyList.Count >= capacity) { var lastNode = _historyList.Last; if (lastNode is not null) { _historyMap.Remove(lastNode.Value); _historyList.RemoveLast(); } } _historyList.AddFirst(visitValue); _historyMap[visitValue] = content; } public List Export() => [.. _historyList.Select(history => _historyMap[history])]; }