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

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

//**************************************************************************************************
partial class HArray2D {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static int? IndexOf<T>( T[,] array, int dimension, int subarrayIdx,
                               T value )
{
   return IndexOf( array, dimension, subarrayIdx, value, null, null, false );
}

public static int? IndexOf<T>( T[,] array, int dimension, int subarrayIdx,
                               T value, int? startIdx )
{
   return IndexOf( array, dimension, subarrayIdx, value, startIdx, null, false );
}

public static int? IndexOf<T>( T[,] array, int dimension, int subarrayIdx,
                               T value, int? startIdx, int? count )
{
   return IndexOf( array, dimension, subarrayIdx, value, startIdx, count, false );
}

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

public static int? LastIndexOf<T>( T[,] array, int dimension, int subarrayIdx,
                                   T value )
{
   return IndexOf( array, dimension, subarrayIdx, value, null, null, true );
}

public static int? LastIndexOf<T>( T[,] array, int dimension, int subarrayIdx,
                                   T value, int? startIdx )
{
   return IndexOf( array, dimension, subarrayIdx, value, startIdx, null, true );
}

public static int? LastIndexOf<T>( T[,] array, int dimension, int subarrayIdx,
                                   T value, int? startIdx, int? count )
{
   return IndexOf( array, dimension, subarrayIdx, value, startIdx, count, true );
}

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

public static int StrictIndexOf<T>( T[,] array, int dimension, int subarrayIdx,
                                    T value )
{
   return StrictIndexOf( array, dimension, subarrayIdx, value, null, null, false );
}

public static int StrictIndexOf<T>( T[,] array, int dimension, int subarrayIdx,
                                    T value, int? startIdx )
{
   return StrictIndexOf( array, dimension, subarrayIdx, value, startIdx, null, false );
}

public static int StrictIndexOf<T>( T[,] array, int dimension, int subarrayIdx,
                                    T value, int? startIdx, int? count )
{
   return StrictIndexOf( array, dimension, subarrayIdx, value, startIdx, count, false );
}

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

public static int StrictLastIndexOf<T>( T[,] array, int dimension, int subarrayIdx,
                                        T value )
{
   return StrictIndexOf( array, dimension, subarrayIdx, value, null, null, true );
}

public static int StrictLastIndexOf<T>( T[,] array, int dimension, int subarrayIdx,
                                        T value, int? startIdx )
{
   return StrictIndexOf( array, dimension, subarrayIdx, value, startIdx, null, true );
}

public static int StrictLastIndexOf<T>( T[,] array, int dimension, int subarrayIdx,
                                        T value, int? startIdx, int? count )
{
   return StrictIndexOf( array, dimension, subarrayIdx, value, startIdx, count, true );
}

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

static int? IndexOf<T>( T[,] array, int dimension, int subarrayIdx,
                        T value, int? startIdx, int? count, bool backwardScan )
{
   return FindIndex
   (
      array, dimension, subarrayIdx,
      (Predicate<T>)delegate (T element)
      {
         return object.Equals(element,value);
      },
      startIdx, count, backwardScan
   );
}

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

static int StrictIndexOf<T>( T[,] array, int dimension, int subarrayIdx,
                             T value, int? startIdx, int? count, bool backwardScan )
                             
{
   int? idx = IndexOf(array,dimension,subarrayIdx,value,startIdx,count,backwardScan);
   if (idx!=null)
      return idx.Value;
   throw new HElementNotFoundException();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HArray2D
//**************************************************************************************************

} // CommonHelpers (.WASM)
