//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// CommonHelpers satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Collections;
using System.Collections.Generic;

#if !WASM
namespace CommonHelpers {
#else
namespace CommonHelpers.WASM {
#endif

//**************************************************************************************************
/// <summary>
/// </summary>
partial class HSimpleDictionary<TKey,TValue> {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public bool TryGetValue(TKey key,out TValue value)
{
   var val = default( TValue );
   bool exists = Access(delegate{
      return _Dictionary_.TryGetValue( key, out val );
   });
   value = val;
   return exists;
}

/// <exception cref="KeyNotFoundException" />
public TValue StrictGetValue(TKey key)
{
   return Access(delegate{
      return _Dictionary_.StrictGetValue( key );
   });
}

//==================================================================================================

public KeyValuePair<TKey,TValue>[] ToArray(bool orderedByKey=true)
{
   return Access(delegate{
      return _Dictionary_.ToArray( orderedByKey );
   });
}

public KeyValuePair<TKey,TValue>[] ToArray([HOptional] Comparison<TKey> keyComparison)
{
   return Access(delegate{
      return _Dictionary_.ToArray( keyComparison );
   });
}

public KeyValuePair<TKey,TValue>[] ToArray([HOptional] IComparer<TKey> keyComparer)
{
   return Access(delegate{
      return _Dictionary_.ToArray( keyComparer );
   });
}

//==================================================================================================

public List<KeyValuePair<TKey,TValue>> ToList(bool orderedByKey=true)
{
   return Access(delegate{
      return _Dictionary_.ToList( orderedByKey );
   });
}

public List<KeyValuePair<TKey,TValue>> ToList([HOptional] Comparison<TKey> keyComparison)
{
   return Access(delegate{
      return _Dictionary_.ToList( keyComparison );
   });
}

public List<KeyValuePair<TKey,TValue>> ToList([HOptional] IComparer<TKey> keyComparer)
{
   return Access(delegate{
      return _Dictionary_.ToList( keyComparer );
   });
}

public List<KeyValuePair<TKey,TValue>> ToList([HOptional] IComparer keyComparer)
{
   return Access(delegate{
      return _Dictionary_.ToList( keyComparer );
   });
}

//==================================================================================================

/// <exception cref="HReadonlyObjectAccessException" />
public void Add(TKey key,TValue value)
{
   Access(true,delegate{
      _Dictionary_.Add( key, value );
   });
}
/// <exception cref="HReadonlyObjectAccessException" />
public void AddKeyValuePair(KeyValuePair<TKey,TValue> keyValuePair)
{
   Access(true,delegate{
      _Dictionary_.AddKeyValuePair( keyValuePair );
   });
}

public bool ContainsKey(TKey key)
{
   return Access(delegate{
      return _Dictionary_.ContainsKey( key );
   });
}
public bool ContainsValue(TValue value)
{
   return Access(delegate{
      return _Dictionary_.ContainsValue( value );
   });
}

/// <exception cref="HReadonlyObjectAccessException" />
public bool Remove(TKey key)
{
   return Access(true,delegate{
      return _Dictionary_.Remove( key );
   });
}

//--------------------------------------------------------------------------------------------------

/// <exception cref="HReadonlyObjectAccessException" />
public void Clear()
{
   Access(true,delegate{
      _Dictionary_.Clear();
   });
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HSimpleDictionary<TKey,TValue>
//**************************************************************************************************

} // CommonHelpers (.WASM)
