mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-08-10 20:27:51 +02:00
Split main project into core,graphics and chocolarm4 subproject (#29)
This commit is contained in:
53
Ryujinx.Core/OsHle/Utilities/IdPool.cs
Normal file
53
Ryujinx.Core/OsHle/Utilities/IdPool.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ryujinx.Core.OsHle.Utilities
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user