static EqualityComparers() { CategoryComparer = new EqualityComparer<Category>(); CategoryItemComparer = new EqualityComparer<CategoryItem>(); ProgramCategoryComparer = new EqualityComparer<ProgramCategory>(); ProgramItemComparer = new EqualityComparer<ProgramItem>(); }
public void Compare() { var comparer1 = new EqualityComparer<Tuple<int, int>>(a => new IComparable[]{a.Item1, a.Item2}); var comparer2 = new EqualityComparer<Tuple<int, int>>(a => a.Item1, a => a.Item2); for (int i = 0; i < 10; i++) { Assert.True(comparer1.Equals(Tuple.Create(i, i), Tuple.Create(i, i))); Assert.True(comparer2.Equals(Tuple.Create(i, i), Tuple.Create(i, i))); Assert.False(comparer1.Equals(Tuple.Create(i, i), Tuple.Create(i + 1, i))); Assert.False(comparer2.Equals(Tuple.Create(i, i), Tuple.Create(i + 1, i))); Assert.False(comparer1.Equals(Tuple.Create(i, i), Tuple.Create(i, i + 1))); Assert.False(comparer2.Equals(Tuple.Create(i, i), Tuple.Create(i, i + 1))); } }
public void Compare_ShouldCompareOnlyIntValue_WhenCalled(int intValue1, string stringValue1, int intValue2, string stringValue2, bool result) { var sut = new EqualityComparer<TestClass>((t1, t2) => t1.TestInt == t2.TestInt); var testObj1 = new TestClass { TestInt = intValue1, TestString = stringValue1 }; var testObj2 = new TestClass { TestInt = intValue2, TestString = stringValue2 }; Assert.AreEqual(result, sut.Equals(testObj1, testObj2)); }
/// <summary> /// Equals protocol. /// </summary> /// <param name="other">Other matrix.</param> /// <param name="comparer">Comparer to elements.</param> /// <returns>TRUE: if matrix are equals.</returns> public bool Equals(Matrix <T> other, EqualityComparer <T> comparer) { if (comparer == null) { comparer = EqualityComparer <T> .Default; } if (other == null) { return(false); } if (this.Rank != other.Rank) { return(false); } if (this.GetType() != other.GetType()) { return(false); } return(this.ContentEquals(other, comparer)); }
/// <summary> /// Checks to see if the array contains the values stored in compareTo at the specified index. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="source">Array to check</param> /// <param name="sourceIndex">Position in the array to check.</param> /// <param name="compareTo">The array to compare to.</param> /// <returns>True if the values in compareTo are in the array at the specified index.</returns> public static bool Contains <T>(T[] source, int sourceIndex, T[] compareTo) { if (source == null || compareTo == null) { return(false); } if (sourceIndex < 0 || sourceIndex + compareTo.Length > source.Length) { return(false); } EqualityComparer <T> comparer = EqualityComparer <T> .Default; for (int i = 0; i < compareTo.Length; i++) { if (!comparer.Equals(source[sourceIndex + i], compareTo[i])) { return(false); } } return(true); }
public static bool ListEquals <T>(IList <T> a, IList <T> b) { if (a == null || b == null) { return(a == null && b == null); } if (a.Count != b.Count) { return(false); } EqualityComparer <T> comparer = EqualityComparer <T> .Default; for (int i = 0; i < a.Count; i++) { if (!comparer.Equals(a[i], b[i])) { return(false); } } return(true); }
public bool Contains(T item) { if (item == null) { for (int i = 0; i < _size; i++) { if (_items[i].v == null) { return(true); } } return(false); } EqualityComparer <T> @default = EqualityComparer <T> .Default; for (int j = 0; j < _size; j++) { if (@default.Equals(_items[j].v, item)) { return(true); } } return(false); }
// Token: 0x06004285 RID: 17029 RVA: 0x000F52FC File Offset: 0x000F34FC public bool Contains(T item) { if (item == null) { for (int i = 0; i < this.count; i++) { if (this.items[i] == null) { return(true); } } return(false); } EqualityComparer <T> @default = EqualityComparer <T> .Default; for (int j = 0; j < this.count; j++) { if (@default.Equals(this.items[j], item)) { return(true); } } return(false); }
public static bool Equals <TKey, TValue>(IReadOnlyDictionary <TKey, TValue>?lhs, IReadOnlyDictionary <TKey, TValue>?rhs) { if (ReferenceEquals(lhs, rhs)) { return(true); } if (lhs == null || rhs == null || lhs.Count != rhs.Count) { return(false); } EqualityComparer <TValue> comparer = EqualityComparer <TValue> .Default; foreach (KeyValuePair <TKey, TValue> entry in lhs) { if (!rhs.TryGetValue(entry.Key, out TValue value) || !comparer.Equals(entry.Value, value)) { return(false); } } return(true); }
public bool Contains(T item) { if (item == null) { for (int j = 0; j < Count; j++) { if (Items[j] == null) { return(true); } } return(false); } EqualityComparer <T> comparer = EqualityComparer <T> .Default; for (int i = 0; i < Count; i++) { if (comparer.Equals(Items[i], item)) { return(true); } } return(false); }
/// <summary> /// 是否完全相等 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="list">待比较列表</param> /// <param name="other">待比较列表</param> /// <returns></returns> public static bool EqualsAll <T>(this IList <T> list, IList <T> other) { if (list == null || other == null) { return(list == null && other == null); } if (list.Count != other.Count) { return(false); } EqualityComparer <T> comparer = EqualityComparer <T> .Default; for (int i = 0; i < list.Count; i++) { if (!comparer.Equals(list[i], other[i])) { return(false); } } return(true); }
internal GroupEnumerator(LocalList <T> list, Func <T, TKey> keySelector, EqualityComparer <TKey> comparer) { var values = new LocalList <Row <TKey, T> >(list.Length); var uniqueKeys = new LocalList <TKey>(); for (var i = 0; i < list.Length; i++) { var element = list.Get(i); var key = keySelector(element); values.Add(new Row <TKey, T>(key, element)); if (!uniqueKeys.Contains(key, comparer)) { uniqueKeys.Add(key); } } _comparer = comparer; _current = default; _position = 0; _values = values; _uniqueKeys = uniqueKeys; }
public static int Level <T>(T node, Func <T, T> parentSelector) { if (node == null) { throw new ArgumentNullException(nameof(node)); } if (parentSelector == null) { throw new ArgumentNullException(nameof(parentSelector)); } EqualityComparer <T> comparer = EqualityComparer <T> .Default; var level = 0; T parent; while (!comparer.Equals(parent = parentSelector(node), default)) { node = parent; level++; } return(level); }
public bool Contains(T item) { if (item == null) { for (int i = 0; i < this._size; i++) { if (this._items[i] == null) { return(true); } } return(false); } EqualityComparer <T> comparer = EqualityComparer <T> .Default; for (int j = 0; j < this._size; j++) { if (comparer.Equals(this._items[j], item)) { return(true); } } return(false); }
// Contains returns true if the specified element is in the List. // It does a linear, O(n) search. Equality is determined by calling // item.Equals(). // public bool Contains(T item) { if (item == null) { for (int i = 0; i < _size; i++) { if (_items[i] == null) { return(true); } } return(false); } EqualityComparer <T> c = EqualityComparer <T> .Default; for (int i = 0; i < _size; i++) { if (c.Equals(_items[i], item)) { return(true); } } return(false); }
/// <summary> /// Checks if an item is in the queue. /// </summary> /// <param name="item">The object to check for in the queue.</param> /// <returns>True if the item is found, false otherwise.</returns> public bool Contains(T item) { // Use the default equality comparer for the type T. EqualityComparer <T> comparer = EqualityComparer <T> .Default; QueueNode <T> node = _first; // If there are items in the queue. if (node != null) { if (item != null) { do { // Use the equality comparer if the item isn't null. if (comparer.Equals(node.Value, item)) { return(true); } node = node.Next; } while (node != null); } else { do { if (node.Value == null) { return(true); } node = node.Next; } while (node != null); } } return(false); }
// Non CxFastList Methods public CxFastListNode <T> Find(T value) { // start at head CxFastListNode <T> head = _head; EqualityComparer <T> comparer = EqualityComparer <T> .Default; if (head != null) { if (value != null) { do { if (comparer.Equals(head._elt, value)) { return(head); } head = head._next; } while (head != _head); } else { do { if (head._elt == null) { return(head); } head = head._next; } while (head != _head); } } return(null); }
public virtual bool Contains(T item) { if (item == null) { for (int num1 = 0; num1 < this.Count; num1++) { if (this[num1] == null) { return(true); } } return(false); } EqualityComparer <T> comparer1 = EqualityComparer <T> .Default; for (int num2 = 0; num2 < this.Count; num2++) { if (comparer1.Equals(this[num2], item)) { return(true); } } return(false); }
public Buffer() { _queue = new Queue <T>(); _comparer = EqualityComparer <T> .Default; }
public Buffer(int capacity) { _queue = new Queue <T>(capacity); _comparer = EqualityComparer <T> .Default; }
/// <summary> /// Constructs and initiates a new <see cref="ThreadedWatcher{T}"/>. Use <see cref="Kill"/>, or return false from the <paramref name="listener"/>, to stop. /// </summary> public ThreadedWatcher(Func <object, T> getter, object container, Func <T, T, bool> listener, int sleepInterval = 10, EqualityComparer <T> comparer = null, Func <Exception, bool> exceptionHandler = null) { this.container = container; this.getter = getter; this.listener = listener; this.sleepInterval = sleepInterval; if (comparer != null) { this.comparer = comparer; } else { this.comparer = EqualityComparer <T> .Default; } this.exceptionHandler = exceptionHandler; val = getter(container); live = true; if (exceptionHandler != null) { new Thread(WatchSafely).Start(); } else { new Thread(Watch).Start(); } }
public MyMultiKeyIndex(Func <TValue, TKey1> keySelector1, Func <TValue, TKey2> keySelector2, int capacity = 0, EqualityComparer <TKey1> keyComparer1 = null, EqualityComparer <TKey2> keyComparer2 = null) { m_index1 = new Dictionary <TKey1, TValue>(capacity, keyComparer1); m_index2 = new Dictionary <TKey2, TValue>(capacity, keyComparer2); KeySelector1 = keySelector1; KeySelector2 = keySelector2; }
public bool Equals(Pair <T> other) { EqualityComparer <T> @default = EqualityComparer <T> .Default; return(@default.Equals(previous, other.Previous) && @default.Equals(current, other.Current)); }
/// <summary> /// Constructs and initiates a new <see cref="ThreadedWatcher{T}"/>. Use <see cref="Kill"/>, or return false from the <paramref name="listener"/>, to stop. /// </summary> public ThreadedWatcher(FieldInfo field, object container, Func <T, T, bool> listener, int sleepInterval = 10, EqualityComparer <T> comparer = null, Func <Exception, bool> exceptionHandler = null) { if (typeof(T).IsAssignableFrom(field.FieldType)) { throw new InvalidOperationException("ThreadedWatcher type T must match the Type of the field being watched!"); } if (!field.IsStatic) { if (container == null) { throw new ArgumentNullException("container", "ThreadedWatcher container must not be null for non-static fields!"); } if (container.GetType() != field.DeclaringType) { throw new ArgumentException("ThreadedWatcher container must of the declaring type of the field being watched!", "container"); } } getter = field.CreateGetter <T>(); this.container = container; this.listener = listener; this.sleepInterval = sleepInterval; if (comparer != null) { this.comparer = comparer; } else { this.comparer = EqualityComparer <T> .Default; } this.exceptionHandler = exceptionHandler; val = getter(container); live = true; if (exceptionHandler != null) { new Thread(WatchSafely).Start(); } else { new Thread(Watch).Start(); } }
protected void TestInsertAsync(TEntity entity, EqualityComparer <TEntity> comparer) { Repo.AddAsync(entity).Wait(); AssertListWithId(DatabaseMock.DaoList, new[] { entity }, comparer); }
protected void TestInsertAsync(IEnumerable <TEntity> entities, EqualityComparer <TEntity> comparer) { Repo.AddAsync(entities).Wait(); AssertListWithId(DatabaseMock.DaoList, entities, comparer); }
/// <summary> /// Helper method to determine if two byte arrays are the same value even if they are different object references /// </summary> /// <param name="binaryValue1">This Object</param> /// <param name="binaryValue2">The Object you want to compare against</param> /// <returns>true if the two objects are equal</returns> public static bool BinaryEquals(this object binaryValue1, object binaryValue2) { return(EqualityComparer.BinaryEquals(binaryValue1, binaryValue2)); }
/// <summary> /// 对象去重 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="list"></param> /// <param name="func"></param> /// <returns></returns> public static IEnumerable <T> ToDist <T>(IEnumerable <T> list, Func <T, T, bool> func) where T : new() { var obj = new EqualityComparer <T>(func); return(list.Distinct(obj)); }
static InsideDefaultEqualityComparer() { EC = EqualityComparer <T> .Default; }
static FileSystemHelper() { byteComparer = EqualityComparer<Byte>.Default; }
public static IEnumerable<MarriageWitness> RemoveDuplicateReferences(this IList<MarriageWitness> list) { var ecP = new EqualityComparer<MarriageWitness>((o1, o2) => o1.Person.ChristianName == o2.Person.ChristianName && o1.Person.Surname == o2.Person.Surname && o1.Person.ReferenceDate == o2.Person.ReferenceDate, o => (o.Person.ReferenceDate.GetHashCode() + o.Person.Surname.GetHashCode() + o.Person.ChristianName.GetHashCode())); IList<MarriageWitness> p = new List<MarriageWitness>(); IList<MarriageWitness> dupes = new List<MarriageWitness>(); int idx = 0; while (idx < list.Count) { if (!p.Contains(list[idx], ecP)) { p.Add(list[idx]); idx++; } else { dupes.Add(list[idx]); list.Remove(list[idx]); } } return dupes; }
public Array2DHashSet(EqualityComparer <T> comparator) : this(comparator, InitalCapacity, InitalBucketCapacity) { }
public Graph(EqualityComparer <T> comparer) { Contract.Requires(comparer != null, "You supplied a null comparer"); _comparer = comparer; }
public Graph() { _comparer = EqualityComparer <T> .Default; }
private static IEnumerable<DynamicBasicBlock> GetDynamicBasicBlocks(IEnumerable<StatementSuspiciousnessInfo> ratedLines) { var TestComparer = new EqualityComparer<ExecutedTest>( (left, right) => left.Name == right.Name, test => test.Name.GetHashCode()); var comparer = new EqualityComparer<IEnumerable<ExecutedTest>>( (left, right) => left.SequenceEqual(right, TestComparer), e => e.SumNoOverflow(t => TestComparer.GetHashCode(t))); IDictionary<IEnumerable<ExecutedTest>, DynamicBasicBlock> dbbs = new Dictionary<IEnumerable<ExecutedTest>, DynamicBasicBlock>(comparer); foreach(StatementSuspiciousnessInfo ratedLine in ratedLines) { DynamicBasicBlock block; if(!dbbs.TryGetValue(ratedLine.Tests, out block)) { block = new DynamicBasicBlock(ratedLine.Tests); dbbs.Add(ratedLine.Tests, block); } block.Lines.Add(ratedLine); ratedLine.DBB = block; } return dbbs.Values; }
public virtual bool Contains( Task t, EqualityComparer <Task> comp) { throw new NotImplementedException(); }
public static IList UniqueSelf(UnaryOpStorage/*!*/ hashStorage, BinaryOpStorage/*!*/ eqlStorage, BlockParam block, IList/*!*/ self) { IEqualityComparer<object> comparer = new EqualityComparer(hashStorage, eqlStorage); var seen = new Dictionary<object, bool>(comparer); bool nilSeen = false; bool modified = false; int i = 0; while (i < self.Count) { object item = self[i]; object key; if (block == null || block.Yield(item, out key)) { key = item; } if (key != null && !seen.ContainsKey(key)) { seen.Add(key, true); i++; } else if (key == null && !nilSeen) { nilSeen = true; i++; } else { // removing objects modifies the array... which breaks the dictionary if "seen" is a self-referential array bool isRecursiveArray = seen.Remove(self); self.RemoveAt(i); modified = true; if (isRecursiveArray) { seen.Add(self, true); // self.hash will change } } } return modified ? self : null; }