juji-io / editscript

A library to diff and patch Clojure/ClojureScript data structures
Eclipse Public License 1.0
485 stars 23 forks source link

Examples in Readme don't produce correct edits #28

Closed crimsonhawk47 closed 2 years ago

crimsonhawk47 commented 2 years ago

Using 0.5.8

The Readme shows this:

(def a [2 {:a 42} 3 {:b 4} {:c 29}])
(def b [{:a 5} {:b 5}])

(diff a b {:algo :quick})
;;==>
;;[[[0] :-]
;; [[0] :-]
;; [[0] :-]
;; [[0 :b] :-]
;; [[0 :a] :+ 5]
;; [[1 :c] :-]
;; [[1 :b] :+ 5]]

(diff a b)
;;==>
;;[[[0] :-]
;; [[0 :a] :r 5]
;; [[1] :-]
;; [[1 :b] :r 5]
;; [[2] :-]
]

However, diffing a and b on my system just produces this EditScript.

[[[] :r [{:a 5} {:b 5}]]]

The quick algo produces the expected result, but every time I diff lists with the A* algorithm, I get just a big replacement of the entire structure

huahaiy commented 2 years ago

The code is correct. The README is incorrect. Thank you for pointing it out.

We have changed the definition of the diff size to reflect the actual size (i.e. the number of nodes in the diff data structure) of the diff. In this particular case, replacing the whole thing has smaller size, just 9, whereas the old diff size was 26. So optimal change is to replace it, for the replacement is very small.