using System;
using System.Collections.Generic;
namespace JM.LinqFaster
{
public static partial class LinqFaster
{
// -------------------------- ARRAYS --------------------------------------------
///
/// Determines whether an array contains a specified element by using the
/// provided IEqualityComparer.
///
/// An array in which to locate a value.
/// The value to locate.
/// An equality comparer to compare values.
/// true if the source sequence contains an element that has the specified value; otherwise, false.
public static bool ContainsF(this TSource[] source, TSource value, IEqualityComparer comparer = null)
{
if (source == null)
{
throw Error.ArgumentNull("source");
}
if (comparer == null)
{
return Array.IndexOf(source, value) != -1;
}
foreach (TSource e in source)
{
if (comparer.Equals(e, value))
{
return true;
}
}
return false;
}
// -------------------------- Lists --------------------------------------------
///
/// Determines whether a list contains a specified element by using the
/// provided IEqualityComparer.
///
/// A list in which to locate a value.
/// The value to locate.
/// An equality comparer to compare values.
/// true if the source sequence contains an element that has the specified value; otherwise, false.
public static bool ContainsF(this List source, TSource value, IEqualityComparer comparer = null)
{
if (source == null)
{
throw Error.ArgumentNull("source");
}
if (comparer == null)
{
return source.IndexOf(value) != -1;
}
for (int i = 0; i < source.Count; i++)
{
if (comparer.Equals(source[i], value))
{
return true;
}
}
return false;
}
}
}