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

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

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

public static bool Exists<T>( T[,] array, int dimension, int subarrayIdx,
                              Predicate<T> match )
{
   return Exists( array, dimension, subarrayIdx, match, null, null, false );
}

public static bool Exists<T>( T[,] array, int dimension, int subarrayIdx,
                              Predicate<T> match, int? startIdx )
{
   return Exists( array, dimension, subarrayIdx, match, startIdx, null, false );
}

public static bool Exists<T>( T[,] array, int dimension, int subarrayIdx,
                              Predicate<T> match, int? startIdx, int? count )
{
   return Exists( array, dimension, subarrayIdx, match, startIdx, count, false );
}

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

public static bool BackwardExists<T>( T[,] array, int dimension,
                                      int subarrayIdx, Predicate<T> match, int? startIdx )
{
   return Exists( array, dimension, subarrayIdx, match, startIdx, null, true );
}

public static bool BackwardExists<T>( T[,] array, int dimension, int subarrayIdx,
                                      Predicate<T> match, int? startIdx, int? count )
{
   return Exists( array, dimension, subarrayIdx, match, startIdx, count, true );
}

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

static bool Exists<T>( T[,] array, int dimension, int subarrayIdx, Predicate<T> match,
                       int? startIdx, int? count, bool backwardScan )
{
   return FindIndex( array, dimension, subarrayIdx, match, startIdx, count ) != null;
}

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

} // CommonHelpers (.WASM)
