예제 #1
0
파일: OurSet.cs 프로젝트: lulzzz/CRDT
        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));
        }
예제 #2
0
파일: OurSet.cs 프로젝트: lulzzz/CRDT
 public bool Equals(OurSet <TKey, TElement> other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     return(ReferenceEquals(this, other) || Equals(_elements, other._elements));
 }
예제 #3
0
파일: OurSet.cs 프로젝트: lulzzz/CRDT
        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));
        }