2018-02-05 00:08:20 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2018-02-20 21:09:23 +01:00
|
|
|
namespace Ryujinx.Core.OsHle.Utilities
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
class IdPool
|
|
|
|
{
|
|
|
|
private HashSet<int> Ids;
|
|
|
|
|
|
|
|
private int CurrId;
|
|
|
|
private int MinId;
|
|
|
|
private int MaxId;
|
|
|
|
|
|
|
|
public IdPool(int Min, int Max)
|
|
|
|
{
|
|
|
|
Ids = new HashSet<int>();
|
|
|
|
|
|
|
|
CurrId = Min;
|
|
|
|
MinId = Min;
|
|
|
|
MaxId = Max;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IdPool() : this(1, int.MaxValue) { }
|
|
|
|
|
|
|
|
public int GenerateId()
|
|
|
|
{
|
|
|
|
lock (Ids)
|
|
|
|
{
|
|
|
|
for (int Cnt = MinId; Cnt < MaxId; Cnt++)
|
|
|
|
{
|
|
|
|
if (Ids.Add(CurrId))
|
|
|
|
{
|
|
|
|
return CurrId;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CurrId++ == MaxId)
|
|
|
|
{
|
|
|
|
CurrId = MinId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool DeleteId(int Id)
|
|
|
|
{
|
|
|
|
lock (Ids)
|
|
|
|
{
|
|
|
|
return Ids.Remove(Id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|