29 lines
512 B
C#
29 lines
512 B
C#
|
using System.Collections.Generic;
|
||
|
|
||
|
namespace Encompass
|
||
|
{
|
||
|
internal class IDManager
|
||
|
{
|
||
|
int nextID = 0;
|
||
|
|
||
|
private Stack<int> availableIDs = new Stack<int>();
|
||
|
|
||
|
public int NextID()
|
||
|
{
|
||
|
if (availableIDs.Count > 0)
|
||
|
{
|
||
|
return availableIDs.Pop();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return nextID++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void Free(int ID)
|
||
|
{
|
||
|
availableIDs.Push(ID);
|
||
|
}
|
||
|
}
|
||
|
}
|