public OurSet <TKey, TElement> Diff(OurSet <TKey, TElement> anotherOurSet) { var mergeResult = Merge(anotherOurSet); var diff = mergeResult.GetElements() .Where(e => !anotherOurSet.GetElements().Contains(e)); return(new OurSet <TKey, TElement>(diff)); }
public bool Equals(OurSet <TKey, TElement> other) { if (ReferenceEquals(null, other)) { return(false); } return(ReferenceEquals(this, other) || Equals(_elements, other._elements)); }
public OurSet <TKey, TElement> Merge(OurSet <TKey, TElement> anotherOurSet) { var unionElementsResult = GetElements().Union(anotherOurSet.GetElements()); var unionGrouped = unionElementsResult .GroupBy(e => e.Id) .ToDictionary(gr => gr.Key, gr => gr); var mergeResult = unionGrouped .Select(u => u.Value.Max()) .OrderBy(v => v.Id) .ThenBy(v => v.Timestamp); return(new OurSet <TKey, TElement>(mergeResult)); }