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

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

//**************************************************************************************************
partial class HArray {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HArray
//**************************************************************************************************

} // CommonHelpers (.WASM)
