public static ShaMapDiff Find(ShaMap a, ShaMap b)
        {
            var diff = new ShaMapDiff(a, b);

            diff.Find();
            return(diff);
        }
        public void Apply(ShaMap sa)
        {
            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var mod in Modified)
            {
                var modded = sa.UpdateItem(mod, B.GetItem(mod).Copy());
                if (!modded)
                {
                    throw new InvalidOperationException();
                }
            }

            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var add in Added)
            {
                var added = sa.AddItem(add, B.GetItem(add).Copy());
                if (!added)
                {
                    throw new InvalidOperationException();
                }
            }
            if (Deleted.Select(sa.RemoveLeaf).Any(removed => !removed))
            {
                throw new InvalidOperationException();
            }
        }
 private ShaMapDiff(ShaMap a,
                    ShaMap b,
                    SortedSet <Hash256> modified = null,
                    SortedSet <Hash256> deleted  = null,
                    SortedSet <Hash256> added    = null)
 {
     A        = a;
     B        = b;
     Modified = modified ?? new SortedSet <Hash256>();
     Deleted  = deleted ?? new SortedSet <Hash256>();
     Added    = added ?? new SortedSet <Hash256>();
 }