2018-02-04 18:08:20 -05:00
|
|
|
using System;
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2018-06-10 20:46:42 -04:00
|
|
|
namespace Ryujinx.HLE.OsHle
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-19 14:58:46 -04:00
|
|
|
class IdDictionary
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
private ConcurrentDictionary<int, object> Objs;
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
public IdDictionary()
|
|
|
|
{
|
2018-02-04 18:08:20 -05:00
|
|
|
Objs = new ConcurrentDictionary<int, object>();
|
|
|
|
}
|
|
|
|
|
2018-03-20 11:18:25 -04:00
|
|
|
public bool Add(int Id, object Data)
|
|
|
|
{
|
|
|
|
return Objs.TryAdd(Id, Data);
|
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
public int Add(object Data)
|
|
|
|
{
|
|
|
|
for (int Id = 1; Id < int.MaxValue; Id++)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-12 00:04:52 -04:00
|
|
|
if (Objs.TryAdd(Id, Data))
|
|
|
|
{
|
|
|
|
return Id;
|
|
|
|
}
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
throw new InvalidOperationException();
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
|
2018-03-12 00:04:52 -04:00
|
|
|
public object GetData(int Id)
|
|
|
|
{
|
|
|
|
if (Objs.TryGetValue(Id, out object Data))
|
|
|
|
{
|
|
|
|
return Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-02-04 18:08:20 -05:00
|
|
|
public T GetData<T>(int Id)
|
|
|
|
{
|
|
|
|
if (Objs.TryGetValue(Id, out object Data) && Data is T)
|
|
|
|
{
|
|
|
|
return (T)Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return default(T);
|
|
|
|
}
|
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
public object Delete(int Id)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
if (Objs.TryRemove(Id, out object Obj))
|
|
|
|
{
|
2018-03-19 14:58:46 -04:00
|
|
|
return Obj;
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
2018-03-12 00:04:52 -04:00
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
return null;
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
public ICollection<object> Clear()
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-03-19 14:58:46 -04:00
|
|
|
ICollection<object> Values = Objs.Values;
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-03-19 14:58:46 -04:00
|
|
|
Objs.Clear();
|
|
|
|
|
|
|
|
return Values;
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|