rokojori_action_library/Runtime/Structures/MultiMap3.cs

71 lines
1.3 KiB
C#

using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using System;
using Godot;
namespace Rokojori
{
public class MultiMap<K1,K2,K3,V>:Map<K1,Map<K2,Map<K3,V>>>
{
public bool Has( K1 key1, K2 key2, K3 key3 )
{
if ( ! ContainsKey( key1 ) )
{
return false;
}
if ( ! this[ key1 ].ContainsKey( key2 ) )
{
return false;
}
return this[ key1 ][ key2 ].ContainsKey( key3 );
}
public V Get( K1 key1, K2 key2, K3 key3 )
{
if ( key1 == null || key2 == null || key3 == null || ! Has( key1, key2, key3 ) )
{
return default(V);
}
return this[ key1 ][ key2 ][ key3 ];
}
public void Set( K1 key, K2 key2, K3 key3, V value )
{
if ( ! ContainsKey( key ) )
{
this[ key ] = new Map<K2,Map<K3,V>>();
this[ key ][ key2 ] = new Map<K3, V>();
}
this[ key ][ key2 ][ key3 ] = value;
}
public void Remove( K1 key, K2 key2, K3 key3, V value )
{
if ( ! Has( key, key2, key3 ) )
{
return;
}
this[ key ][ key2 ].Remove( key3 );
if ( this[ key ][ key2 ].Count == 0 )
{
this[ key ].Remove( key2 );
}
if ( this[ key ].Count == 0 )
{
Remove( key );
}
}
}
}