public void ByteequalityComparerViaBuilder() { SCG.IEqualityComparer <byte> h = C5.EqualityComparer <byte> .Default; byte s = 3; byte t = 3; byte u = 5; Assert.AreEqual(s.GetHashCode(), h.GetHashCode(s)); Assert.IsTrue(h.Equals(s, t)); Assert.IsFalse(h.Equals(s, u)); Assert.AreSame(h, C5.EqualityComparer <byte> .Default); }
public void ValuetypeequalityComparerViaBuilder() { SCG.IEqualityComparer <double> h = C5.EqualityComparer <double> .Default; double s = 3.4; double t = 3.4; double u = 5.7; Assert.AreEqual(s.GetHashCode(), h.GetHashCode(s)); Assert.IsTrue(h.Equals(s, t)); Assert.IsFalse(h.Equals(s, u)); Assert.AreSame(h, C5.EqualityComparer <double> .Default); }
public void CharequalityComparerViaBuilder() { SCG.IEqualityComparer <char> h = C5.EqualityComparer <char> .Default; char s = 'å'; char t = 'å'; char u = 'r'; Assert.AreEqual(s.GetHashCode(), h.GetHashCode(s)); Assert.IsTrue(h.Equals(s, t)); Assert.IsFalse(h.Equals(s, u)); Assert.AreSame(h, C5.EqualityComparer <char> .Default); }
public void LongequalityComparerViaBuilder() { SCG.IEqualityComparer <long> h = C5.EqualityComparer <long> .Default; long s = 3; long t = 3; long u = -500000000000000L; Assert.AreEqual(s.GetHashCode(), h.GetHashCode(s)); Assert.IsTrue(h.Equals(s, t)); Assert.IsFalse(h.Equals(s, u)); Assert.AreSame(h, C5.EqualityComparer <long> .Default); }
public void ReftypeequalityComparerViaBuilder() { SCG.IEqualityComparer <string> h = C5.EqualityComparer <string> .Default; string s = "bamse"; string t = "bamse"; string u = "bimse"; Assert.AreEqual(s.GetHashCode(), h.GetHashCode(s)); Assert.IsTrue(h.Equals(s, t)); Assert.IsFalse(h.Equals(s, u)); Assert.AreSame(h, C5.EqualityComparer <string> .Default); }
public void DoubleequalityComparerViaBuilder() { SCG.IEqualityComparer <double> h = EqualityComparer <double> .Default; double s = 3.12345; double t = 3.12345; double u = -5.2; Assert.AreEqual(s.GetHashCode(), h.GetHashCode(s)); Assert.IsTrue(h.Equals(s, t)); Assert.IsFalse(h.Equals(s, u)); Assert.AreSame(h, EqualityComparer <double> .Default); }
public void DecimalequalityComparerViaBuilder() { SCG.IEqualityComparer <decimal> h = EqualityComparer <decimal> .Default; decimal s = 3.0001M; decimal t = 3.0001M; decimal u = -500000000000000M; Assert.AreEqual(s.GetHashCode(), h.GetHashCode(s)); Assert.IsTrue(h.Equals(s, t)); Assert.IsFalse(h.Equals(s, u)); Assert.AreSame(h, EqualityComparer <decimal> .Default); }
public void FloatequalityComparerViaBuilder() { SCG.IEqualityComparer <float> h = EqualityComparer <float> .Default; float s = 3.1F; float t = 3.1F; float u = -5.2F; Assert.AreEqual(s.GetHashCode(), h.GetHashCode(s)); Assert.IsTrue(h.Equals(s, t)); Assert.IsFalse(h.Equals(s, u)); Assert.AreSame(h, EqualityComparer <float> .Default); }
public void UlongequalityComparerViaBuilder() { SCG.IEqualityComparer <ulong> h = EqualityComparer <ulong> .Default; ulong s = 3; ulong t = 3; ulong u = 500000000000000UL; Assert.AreEqual(s.GetHashCode(), h.GetHashCode(s)); Assert.IsTrue(h.Equals(s, t)); Assert.IsFalse(h.Equals(s, u)); Assert.AreSame(h, EqualityComparer <ulong> .Default); }
public void UintequalityComparerViaBuilder() { SCG.IEqualityComparer <uint> h = EqualityComparer <uint> .Default; uint s = 3; uint t = 3; uint u = 3000000000; Assert.AreEqual(s.GetHashCode(), h.GetHashCode(s)); Assert.IsTrue(h.Equals(s, t)); Assert.IsFalse(h.Equals(s, u)); Assert.AreSame(h, EqualityComparer <uint> .Default); }
public void ShortequalityComparerViaBuilder() { SCG.IEqualityComparer <short> h = C5.EqualityComparer <short> .Default; short s = 3; short t = 3; short u = -5; Assert.AreEqual(s.GetHashCode(), h.GetHashCode(s)); Assert.IsTrue(h.Equals(s, t)); Assert.IsFalse(h.Equals(s, u)); Assert.AreSame(h, C5.EqualityComparer <short> .Default); }
public GlobalLockDEPQ(int capacity) { this.comparer = SCG.Comparer <T> .Default; this.itemEquelityComparer = SCG.EqualityComparer <T> .Default; int lenght = 1; while (lenght < capacity) { lenght <<= 1; //lenght is always equal to 2 power by some number. } heap = new Interval[lenght]; }
/// <summary> /// Create an empty ArrayBase object. /// </summary> /// <param name="capacity">The initial capacity of the internal array container. /// Will be rounded upwards to the nearest power of 2 greater than or equal to 8.</param> /// <param name="itemequalityComparer">The item equalityComparer to use, primarily for item equality</param> /// <param name="memoryType">The type of memory for the enumerator used to iterate the collection</param> protected ArrayBase(int capacity, SCG.IEqualityComparer <T> itemequalityComparer, MemoryType memoryType) : base(itemequalityComparer, memoryType) { int newlength = 8; while (newlength < capacity) { newlength *= 2; } array = new T[newlength]; _internalEnumerator = new Enumerator(this, memoryType); }
private IntervalHeap(int capacity, SCG.IComparer <T> comparer, SCG.IEqualityComparer <T> itemequalityComparer) { this.comparer = comparer ?? throw new NullReferenceException("Item comparer cannot be null"); this.itemequalityComparer = itemequalityComparer ?? throw new NullReferenceException("Item equality comparer cannot be null"); int length = 1; while (length < capacity) { length <<= 1; } heap = new Interval[length]; }
public void LinkedHashSet_Generic_Constructor_NullIEqualityComparer() { SCG.IEqualityComparer <T> comparer = null; LinkedHashSet <T> set = new LinkedHashSet <T>(comparer); if (comparer == null) { Assert.Equal(EqualityComparer <T> .Default, set.EqualityComparer); } else { Assert.Equal(comparer, set.EqualityComparer); } }
public void UnseqequalityComparerViaBuilder() { SCG.IEqualityComparer <ICollection <int> > h = EqualityComparer <ICollection <int> > .Default; ICollection <int> s = new LinkedList <int>(); ICollection <int> t = new LinkedList <int>(); 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, EqualityComparer <ICollection <int> > .Default); }
public void LinkedHashSet_Generic_Constructor_int_IEqualityComparer(int capacity) { SCG.IEqualityComparer <T> comparer = GetIEqualityComparer(); LinkedHashSet <T> set = new LinkedHashSet <T>(capacity, comparer); Assert.Equal(0, set.Count); if (comparer == null) { Assert.Equal(EqualityComparer <T> .Default, set.EqualityComparer); } else { Assert.Equal(comparer, set.EqualityComparer); } }
private IntervalHeap(int capacity, SCG.IComparer <T> comparer, SCG.IEqualityComparer <T> itemequalityComparer) { if (comparer == null) { throw new NullReferenceException("Item comparer cannot be null"); } if (itemequalityComparer == null) { throw new NullReferenceException("Item equality comparer cannot be null"); } this.comparer = comparer; this.itemequalityComparer = itemequalityComparer; Clear(capacity); }
public RelaxedLotanShavitSkipList(int max) { comparer = SCG.Comparer <T> .Default; itemEquelityComparer = SCG.EqualityComparer <T> .Default; maxLevel = max; size = 0; level = 1; header = new Node(maxLevel, default(T)); header.deleted = 2; tail = new Node(0, default(T), true); tail.deleted = 2; for (int i = 0; i < maxLevel; i++) { header.forward[i] = tail; } }
// 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); }
// Given a sequence of strings, return only the first member of each // anagram class. public static SCG.IEnumerable <String> FirstAnagramOnly(SCG.IEnumerable <String> ss) { SCG.IEqualityComparer <TreeBag <char> > tbh = UnsequencedCollectionEqualityComparer <TreeBag <char>, char> .Default; HashSet <TreeBag <char> > anagrams = new HashSet <TreeBag <char> >(tbh); foreach (String s in ss) { TreeBag <char> anagram = AnagramClass(s); if (!anagrams.Contains(anagram)) { anagrams.Add(anagram); yield return(s); } } }
public GlobalLockSkipList(int maxlevel) { this.comparer = SCG.Comparer <T> .Default; this.itemEquelityComparer = SCG.EqualityComparer <T> .Default; header = null; int max = 1; while (max < maxlevel) { max <<= 1; } maxLevel = max; level = 0; header = new Node(maxLevel, default(T)); rng = new Random(); }
public HuntLockDEPQv3(int capacity) { this.comparer = SCG.Comparer <T> .Default; this.itemEquelityComparer = SCG.EqualityComparer <T> .Default; int lenght = 1; while (lenght < capacity) { lenght <<= 1; } heap = new Interval[lenght]; locks = new object[lenght]; for (int i = 0; i < lenght; i++) { heap[i] = new Interval(); locks[i] = heap[i].intervalLock; } }
public static int IndexOf <T>(this T[] array, T item, SCG.IEqualityComparer <T> equalityComparer = null) { Contract.Requires(array.Contains(item, equalityComparer)); if (equalityComparer == null) { equalityComparer = SCG.EqualityComparer <T> .Default; } for (var i = 0; i < array.Length; i++) { if (equalityComparer.Equals(array[i], item)) { return(i); } } throw new Exception(); }
public static HashSet <int> MakeRandom(int count, SCG.IEqualityComparer <int> eqc) { HashSet <int> res; if (eqc == null) { res = new HashSet <int>(); } else { res = new HashSet <int>(eqc); } for (int i = 0; i < count; i++) { res.Add(rnd.Next(1000000)); } return(res); }
public HuntLockDEPQv1(int capacity) { this.comparer = SCG.Comparer <T> .Default; this.itemEquelityComparer = SCG.EqualityComparer <T> .Default; size = 0; int length = 1; while (length < capacity) { length <<= 1; } minheap = new Interval[length]; locks = new object[length]; for (int i = 0; i < length; i++) { Interval interval = new Interval(); minheap[i] = interval; locks[i] = interval.intervalLock; } }
/// <summary> /// Create a hash set with external item equalityComparer. /// </summary> /// <param name="capacity">Initial table size (rounded to power of 2, at least 16)</param> /// <param name="fill">Fill threshold (in range 10% to 90%)</param> /// <param name="itemequalityComparer">The external item equalitySCG.Comparer</param> public HashSet(int capacity, double fill, SCG.IEqualityComparer <T> itemequalityComparer) : base(itemequalityComparer) { _randomhashfactor = (Debug.UseDeterministicHashing) ? 1529784659 : (2 * (uint)Random.Next() + 1) * 1529784659; if (fill < 0.1 || fill > 0.9) { throw new ArgumentException("Fill outside valid range [0.1, 0.9]"); } if (capacity <= 0) { throw new ArgumentException("Capacity must be non-negative"); } //this.itemequalityComparer = itemequalityComparer; origbits = 4; while (capacity - 1 >> origbits > 0) { origbits++; } clear(); }
public ExpectedDirectedCollectionValue(SCG.IEnumerable <T> items, SCG.IEqualityComparer <T> equalityComparer, bool allowsNull, Func <T> chooseFunction = null, EnumerationDirection direction = EnumerationDirection.Forwards) : base(items, equalityComparer, allowsNull, chooseFunction) { #region Code Contracts // Argument must be non-null Requires(items != null, ArgumentMustBeNonNull); // Argument must be non-null Requires(equalityComparer != null, ArgumentMustBeNonNull); // All items must be non-null if collection disallows null values Requires(allowsNull || ForAll(items, item => item != null), ItemsMustBeNonNull); // Argument must be valid enum constant Requires(Enum.IsDefined(typeof(EnumerationDirection), direction), EnumMustBeDefined); #endregion Direction = direction; }
public HellerSkipListv2(int maxlevel) { this.comparer = SCG.Comparer <T> .Default; this.itemEquelityComparer = SCG.EqualityComparer <T> .Default; header = null; int max = 1; while (max < maxlevel) { max <<= 1; } maxLevel = max; tail = new Node(maxLevel - 1, default(T)); tail.tail = true; header = new Node(maxLevel - 1, default(T)); for (int i = 0; i < maxLevel; i++) { header.forward[i] = tail; tail.forward[i] = tail; } }
public static int GetSequencedHashCode <T>(this ISequenced <T> items, SCG.IEqualityComparer <T> equalityComparer = null) { if (items == null) { return(0); // TODO: Better default value? } if (equalityComparer == null) { equalityComparer = SCG.EqualityComparer <T> .Default; } var hashCode = 0; // TODO: Better intial value? foreach (var item in items) { hashCode = hashCode * HashFactor + equalityComparer.GetHashCode(item); } return(hashCode); }