public bool Equals(T x, T y) { var boiler = EqualityHelper.BoilerEquality(x, y); if (boiler.IsSome) { return(boiler.Value); } return(EqualityFunction(x, y)); }
/// <summary> /// Returns true if this sequence is equal to the other sequence, using an optional value equality comparer. /// </summary> /// <param name="other"></param> /// <param name="eq"></param> /// <returns></returns> public virtual bool SequenceEquals(IEnumerable <TElem> other, IEqualityComparer <TElem> eq = null) { other.CheckNotNull("other"); TList list = other as TList; if (list != null) { return(SequenceEquals(list, eq)); } return(EqualityHelper.SeqEquals(this, other, eq)); }
/// <summary> /// Determines structural equality between the sequential collections. /// </summary> /// <param name="a">The first collection</param> /// <param name="b">The second collection.</param> /// <returns> /// Whether the two collections are equal. /// </returns> public static bool operator ==(AbstractSequential <TElem, TList> a, AbstractSequential <TElem, TList> b) { var boiler = EqualityHelper.BoilerEquality(a, b); if (boiler.IsSome) { return(boiler.Value); } return (a.Equals(b)); }
/// <summary> /// Returns an equality comparer for sequences, determining equality sequentially. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="eq">Optionally, an equality comparer for the elements. Otherwise, the default equality comparer is used.</param> /// <returns></returns> public static IEqualityComparer <IEnumerable <T> > SequenceEquality <T>(IEqualityComparer <T> eq = null) { return(CreateEqComparer <IEnumerable <T> >((x, y) => EqualityHelper.SeqEquals(x, y, eq), x => EqualityHelper.SeqHashCode(x, eq))); }
/// <summary> /// Returns a lexicographic sequence comparer, which compares each element according to its position, from first to /// last. /// </summary> /// <typeparam name="T">The type of element being compared. Must be IComparable[T].</typeparam> /// <returns></returns> public static IComparer <IEnumerable <T> > LexSequenceComparer <T>() where T : IComparable <T> { return(CreateComparer <IEnumerable <T> >((x, y) => EqualityHelper.SeqCompareLex(x, y))); }
/// <summary> /// Returns a lexicographic sequence comparer, which compares each element according to its position, from first to /// last. /// </summary> /// <param name="comparer">The comparer used to compare each element of the sequence.</param> /// <returns></returns> public static IComparer <IEnumerable <T> > LexSequenceComparer <T>(IComparer <T> comparer) { return(CreateComparer <IEnumerable <T> >((x, y) => EqualityHelper.SeqCompareLex(x, y, comparer))); }
/// <summary> /// Determines whether this sequence is bigger than the other using number-like comparison (length first, then /// lexicographically). /// </summary> /// <typeparam name="T">The type of value.</typeparam> /// <param name="first">The first sequence, which is compared to the second sequence.</param> /// <param name="second">The second sequence.</param> /// <returns></returns> public static int NumCompare <T>(this IEnumerable <T> first, IEnumerable <T> second) where T : IComparable <T> { return(EqualityHelper.SeqCompareNum(first, second)); }
/// <summary> /// Determines whether this sequence is bigger than the other using number-like comparison (length first, then /// lexicographically). /// </summary> /// <typeparam name="T">The type of value.</typeparam> /// <param name="first">The first sequence, which is compared to the second sequence</param> /// <param name="second">The second sequence.</param> /// <param name="comparer">The comparer.</param> /// <returns></returns> public static int NumCompare <T>(this IEnumerable <T> first, IEnumerable <T> second, IComparer <T> comparer) { return(EqualityHelper.SeqCompareNum(first, second, comparer)); }
/// <summary> /// Determines whether this sequence is bigger than the other using lexicographic comparison. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="self"></param> /// <param name="other"></param> /// <returns></returns> public static int LexCompare <T>(this IEnumerable <T> self, IEnumerable <T> other) where T : IComparable <T> { return(EqualityHelper.SeqCompareLex(self, other)); }
/// <summary> /// Determines whether this sequence is bigger than the other using a lexicographic comparison (comparing each element /// based on its position, from first to last). /// </summary> /// <typeparam name="T"></typeparam> /// <param name="self"></param> /// <param name="other"></param> /// <param name="comparer"></param> /// <returns></returns> public static int LexCompare <T>(this IEnumerable <T> self, IEnumerable <T> other, IComparer <T> comparer) { return(EqualityHelper.SeqCompareLex(self, other, comparer)); }
/// <summary> /// Determines equality between sequences of key-value pairs. That is, they must have the same key-value pairs, but the /// multiplicity of each key-value pair doesn't matter. /// </summary> /// <typeparam name="TKey">The type of key.</typeparam> /// <typeparam name="TValue">The type of the value.</typeparam> /// <param name="self">The first sequence of key-value pairs.</param> /// <param name="other">The second sequence of key-value pairs.</param> /// <param name="vEq">The equality comparer used to compare the values..</param> /// <returns></returns> public static bool MapEquals <TKey, TValue>(this IEnumerable <KeyValuePair <TKey, TValue> > self, IEnumerable <KeyValuePair <TKey, TValue> > other, IEqualityComparer <TValue> vEq = null) { return(EqualityHelper.MapEquals(self, other, vEq)); }
/// <summary> /// Determines set equality between sequences. That is, they must contain the same elements, but the multiplicity of /// each element doesn't matter. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="self">The self.</param> /// <param name="other">The other.</param> /// <param name="eq">Optionally, the equality comparer used for the values. If not specified, the default equality comparer is used.</param> /// <returns></returns> public static bool SetEquals <T>(this IEnumerable <T> self, IEnumerable <T> other, IEqualityComparer <T> eq = null) { return(EqualityHelper.SetEquals(self, other, eq)); }
/// <summary> /// Computes a hash code for a sequence. /// </summary> /// <typeparam name="T">The type of value.</typeparam> /// <param name="self">The sequence for which to compute the hash code.</param> /// <param name="eq">The equality comparer used to generate the hash of each element. If not specified, default equality comparer is used.</param> /// <returns></returns> public static int CompuateSeqHashCode <T>(this IEnumerable <T> self, IEqualityComparer <T> eq = null) { return(EqualityHelper.SeqHashCode(self, eq)); }
/// <summary> /// Override this to provide an efficient implementation for the operation. /// </summary> /// <param name="other"></param> /// <param name="eq"></param> /// <returns></returns> protected virtual bool SequenceEquals(TList other, IEqualityComparer <TElem> eq = null) { other.CheckNotNull("other"); return(EqualityHelper.SeqEquals(this, other, eq)); }