namespace SPTarkov.Server.Core.Extensions;
public static class DictionaryExtensions
{
///
/// Add a value by key to a dictionary, if the key doesn't exist, create it
///
/// Dictionary key type
/// Dictionary to add/update
/// Key to update by
/// Value to add to key
public static void AddOrUpdate(this IDictionary dict, T key, double value)
where T : notnull
{
if (!dict.TryAdd(key, value))
{
dict[key] += value;
}
}
///
/// Add a value by key to a dictionary, if the key doesn't exist, create it
///
/// Dictionary key type
/// Dictionary to add/update
/// Key to update by
/// Value to add to key
public static void AddOrUpdate(this IDictionary dict, T key, int value)
where T : notnull
{
if (!dict.TryAdd(key, value))
{
dict[key] += value;
}
}
public static void RemoveItems(this IDictionary collection, ISet idsToRemove)
{
foreach (var key in idsToRemove)
{
collection.Remove(key);
}
}
}