using System.Collections.Generic;
namespace RateLimiter
{
///
/// LinkedList with a limited size
/// If the size exceeds the limit older entry are removed
///
///
public class LimitedSizeStack: LinkedList
{
private readonly int _MaxSize;
///
/// Construct the LimitedSizeStack with the given limit
///
///
public LimitedSizeStack(int maxSize)
{
_MaxSize = maxSize;
}
///
/// Push new entry. If he size exceeds the limit, the oldest entry is removed
///
///
public void Push(T item)
{
AddFirst(item);
if (Count > _MaxSize)
RemoveLast();
}
}
}