rj-action-library/Runtime/Structures/DictionaryList.cs

40 lines
624 B
C#

using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using System;
using Godot;
namespace Rokojori
{
public class DictionaryList<K,V>:Dictionary<K,List<V>>
{
public void Add( K key, V value )
{
if ( ! ContainsKey( key ) )
{
this[ key ] = new List<V>();
}
this[ key ].Add( value );
}
public void Remove( K key, V value )
{
if ( ! ContainsKey( key ) )
{
return;
}
var list = this[ key ];
list.Remove( value );
if ( list.Count == 0 )
{
Remove( key );
}
}
}
}