Files
mirror-processhacker/trunk/ProcessHacker/HistoryManager.cs
T
wj32 0b9b2faa2c * #2675864 - "System Information improvements"
* Full CPU, I/O and memory usage history for processes and the OS
* Tooltips for graphs

git-svn-id: svn://svn.code.sf.net/p/processhacker/code@875 21ef857c-d57f-4fe0-8362-d861dc6d29cd
2009-03-14 09:20:50 +00:00

65 lines
1.9 KiB
C#

/*
* Process Hacker -
* history manager
*
* Copyright (C) 2009 wj32
*
* This file is part of Process Hacker.
*
* Process Hacker is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Process Hacker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
namespace ProcessHacker
{
public class HistoryManager<TKey, TValue>
{
private Dictionary<TKey, List<TValue>> _history = new Dictionary<TKey, List<TValue>>();
private int _maxCount = 400;
public int MaxCount
{
get { return _maxCount; }
set { _maxCount = value; }
}
public ReadOnlyCollection<TValue> this[TKey key]
{
get { return GetHistory(key); }
}
public void Add(TKey key)
{
_history.Add(key, new List<TValue>());
}
public ReadOnlyCollection<TValue> GetHistory(TKey key)
{
return new ReadOnlyCollection<TValue>(_history[key]);
}
public void Update(TKey key, TValue value)
{
_history[key].Insert(0, value);
if (_history[key].Count > _maxCount)
_history[key].RemoveRange(_history[key].Count - 1, _history[key].Count - _maxCount);
}
}
}