1
1
mirror of https://github.com/github/semantic.git synced 2024-11-25 11:04:00 +03:00

Use the patch constructors in dictionary diffing.

This commit is contained in:
Rob Rix 2015-10-15 11:20:07 -04:00
parent fed0d91d30
commit eda4ece5a8

View File

@ -76,8 +76,8 @@ public enum Algorithm<Term: TermType, B> {
case let .Roll(.ByKey(a, b, f)): case let .Roll(.ByKey(a, b, f)):
// Essentially [set reconciliation](https://en.wikipedia.org/wiki/Data_synchronization#Unordered_data) on the keys, followed by recurring into the values of the intersecting keys. // Essentially [set reconciliation](https://en.wikipedia.org/wiki/Data_synchronization#Unordered_data) on the keys, followed by recurring into the values of the intersecting keys.
let deleted = Set(a.keys).subtract(b.keys).map { ($0, Diff.Pure(Patch.Delete(a[$0]!))) } let deleted = Set(a.keys).subtract(b.keys).map { ($0, Diff.Delete(a[$0]!)) }
let inserted = Set(b.keys).subtract(a.keys).map { ($0, Diff.Pure(Patch.Insert(b[$0]!))) } let inserted = Set(b.keys).subtract(a.keys).map { ($0, Diff.Insert(b[$0]!)) }
let patched = Set(a.keys).intersect(b.keys).map { ($0, recurOrReplace(a[$0]!, b[$0]!)) } let patched = Set(a.keys).intersect(b.keys).map { ($0, recurOrReplace(a[$0]!, b[$0]!)) }
return f(Dictionary(elements: deleted + inserted + patched)).evaluate(equals, recur: recur) return f(Dictionary(elements: deleted + inserted + patched)).evaluate(equals, recur: recur)