using System.Collections.Generic;
namespace JM.LinqFaster
{
public static partial class LinqFaster
{
///
/// Determines whether two sequences are equal by comparing the elements by using the
/// provided comparer or the default equality comparer for their type if none is provided.
///
/// A sequence to compare to second.
/// A sequence to compare to first.
/// An optional Comparer to use for the comparison.
/// true of the two sources are of equal length and their corresponding
/// elements are equal according to the equality comparer. Otherwise, false.
public static bool SequenceEqualF(T[] first, T[] second, IEqualityComparer comparer = null)
{
if (comparer == null)
{
comparer = EqualityComparer.Default;
}
if (first == null)
{
throw Error.ArgumentNull("first");
}
if (second == null)
{
throw Error.ArgumentNull("second");
}
if (first.Length != second.Length) return false;
for (int i = 0; i < first.Length; i++)
{
if (!comparer.Equals(first[i], second[i])) return false;
}
return true;
}
///
/// Determines whether two sequences are equal by comparing the elements by using the
/// provided comparer or the default equality comparer for their type if none is provided.
///
/// A sequence to compare to second.
/// A sequence to compare to first.
/// An optional Comparer to use for the comparison.
/// true of the two sources are of equal length and their corresponding
/// elements are equal according to the equality comparer. Otherwise, false.
public static bool SequenceEqualF(List first, List second, IEqualityComparer comparer = null)
{
if (comparer == null)
{
comparer = EqualityComparer.Default;
}
if (first == null)
{
throw Error.ArgumentNull("first");
}
if (second == null)
{
throw Error.ArgumentNull("second");
}
if (first.Count != second.Count) return false;
for (int i = 0; i < first.Count; i++)
{
if (!comparer.Equals(first[i], second[i])) return false;
}
return true;
}
///
/// Determines whether two sequences are equal by comparing the elements by using the
/// provided comparer or the default equality comparer for their type if none is provided.
///
/// A sequence to compare to second.
/// A sequence to compare to first.
/// An optional Comparer to use for the comparison.
/// true of the two sources are of equal length and their corresponding
/// elements are equal according to the equality comparer. Otherwise, false.
public static bool SequenceEqualF(T[] first, List second, IEqualityComparer comparer = null)
{
if (comparer == null)
{
comparer = EqualityComparer.Default;
}
if (first == null)
{
throw Error.ArgumentNull("first");
}
if (second == null)
{
throw Error.ArgumentNull("second");
}
if (first.Length != second.Count) return false;
for (int i = 0; i < first.Length; i++)
{
if (!comparer.Equals(first[i], second[i])) return false;
}
return true;
}
///
/// Determines whether two sequences are equal by comparing the elements by using the
/// provided comparer or the default equality comparer for their type if none is provided.
///
/// A sequence to compare to second.
/// A sequence to compare to first.
/// An optional Comparer to use for the comparison.
/// true of the two sources are of equal length and their corresponding
/// elements are equal according to the equality comparer. Otherwise, false.
public static bool SequenceEqualF(List first, T[] second, IEqualityComparer comparer = null)
{
if (comparer == null)
{
comparer = EqualityComparer.Default;
}
if (first == null)
{
throw Error.ArgumentNull("first");
}
if (second == null)
{
throw Error.ArgumentNull("second");
}
if (first.Count != second.Length) return false;
for (int i = 0; i < first.Count; i++)
{
if (!comparer.Equals(first[i], second[i])) return false;
}
return true;
}
}
}