Skip to content

Commit

Permalink
simplify equality comparer
Browse files Browse the repository at this point in the history
  • Loading branch information
testfirstcoder authored and BEagle1984 committed Mar 16, 2024
1 parent 5c95b97 commit 0dec3b2
Showing 1 changed file with 2 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,9 @@ public bool Equals(IEnumerable<KeyValuePair<TKey, TValue>>? x, IEnumerable<KeyVa
if (x.Count() != y.Count())
return false;

var allKeys = x.Select(pair => pair.Key)
.Union(y.Select(pair => pair.Key))
.Distinct()
.ToList();
var hashY = y.ToDictionary(pair => pair.Key, pair => pair.Value);

if (allKeys.Count != x.Count())
return false;

foreach (var key in allKeys)
{
var valueX = x.FirstOrDefault(pair => Equals(pair.Key, key));
var valueY = y.FirstOrDefault(pair => Equals(pair.Key, key));

if (!Equals(valueX, valueY))
return false;
}

return true;
return x.All(pairX => hashY.TryGetValue(pairX.Key, out var valueY) && Equals(pairX.Value, valueY));
}

public int GetHashCode(IEnumerable<KeyValuePair<TKey, TValue>> obj) => obj.Count();
Expand Down

0 comments on commit 0dec3b2

Please sign in to comment.