public void UnseqequalityComparerViaBuilder2() { SCG.IEqualityComparer <C5.HashSet <int> > h = C5.EqualityComparer <C5.HashSet <int> > .Default; C5.HashSet <int> s = new C5.HashSet <int>(); s.Add(1); s.Add(2); s.Add(3); Assert.AreEqual(CHC.unsequencedhashcode(1, 2, 3), h.GetHashCode(s)); }
public void SeqequalityComparerViaBuilder3() { SCG.IEqualityComparer <C5.IList <int> > h = C5.EqualityComparer <C5.IList <int> > .Default; C5.IList <int> s = new LinkedList <int>(); s.Add(1); s.Add(2); s.Add(3); Assert.AreEqual(CHC.sequencedhashcode(1, 2, 3), h.GetHashCode(s)); }
public static void Equalities(string msg, SCG.IEqualityComparer <IList <int> > equalityComparer) { Console.WriteLine("\n{0}:", msg); Console.Write("Equals(col1,col2)={0,-5}; ", equalityComparer.Equals(_col1, _col2)); Console.Write("Equals(col1,col3)={0,-5}; ", equalityComparer.Equals(_col1, _col3)); Console.WriteLine("Equals(col2,col3)={0,-5}", equalityComparer.Equals(_col2, _col3)); }
public static HashSet <int> MakeRandom(int count, SCG.IEqualityComparer <int> eqc) { var res = eqc == null ? new HashSet <int>() : new HashSet <int>(eqc); for (var i = 0; i < count; i++) { res.Add(rnd.Next(1000000)); } return(res); }
public void UnseqequalityComparerViaBuilder() { SCG.IEqualityComparer <C5.ICollection <int> > h = C5.EqualityComparer <C5.ICollection <int> > .Default; C5.ICollection <int> s = new LinkedList <int>(); C5.ICollection <int> t = new LinkedList <int>(); C5.ICollection <int> u = new LinkedList <int>(); s.Add(1); s.Add(2); s.Add(3); t.Add(3); t.Add(2); t.Add(1); u.Add(3); u.Add(2); u.Add(4); Assert.AreEqual(s.GetUnsequencedHashCode(), h.GetHashCode(s)); Assert.IsTrue(h.Equals(s, t)); Assert.IsFalse(h.Equals(s, u)); Assert.AreSame(h, C5.EqualityComparer <C5.ICollection <int> > .Default); }
// When colls is a collection of collections, this method checks // that all `inner' collections use the exact same equalityComparer. Note // that two equalityComparer objects may be functionally (extensionally) // identical, yet be distinct objects. However, if the equalityComparers // were obtained from EqualityComparer<T>.Default, there will be at most one // equalityComparer for each type T. public static bool EqualityComparerSanity <T, U>(ICollectionValue <U> colls) where U : IExtensible <T> { SCG.IEqualityComparer <T> equalityComparer = null; foreach (IExtensible <T> coll in colls) { if (equalityComparer == null) { equalityComparer = coll.EqualityComparer; } if (equalityComparer != coll.EqualityComparer) { return(false); } } return(true); }
public DistinctHashBag(SCG.IEqualityComparer <T> eqc) { _dict = new HashDictionary <T, HashSet <T> >(eqc); }