(combine this that)
Concate that editscript onto this editscript, return the new editscript
Concate that editscript onto this editscript, return the new editscript
(diff a b & {:keys [algo] :or {algo :a-star} :as opts})
Create an editscript to represent the transformations needed to turn a
Clojure data structure a
into another Clojure data structure b
.
This function accepts any nested Clojure data structures. In Clojure, those
implement IPersistentVector
, IPersistentMap
, IPersistentList
,
and IPersistentSet
will be treated as collections. The same are true for
the corresponding deftypes in Clojurescript, such as PersistentVector
,
PersistentMap
, and so on. Anything else are treated as atomic values.
The editscript is represented as a vector of basic operations: add :+
,
delete :-
, and replace :r
. Each operation also include a path to the
location of the operation, which is similar to the path vector in update-in
.
However, editscript path works for all above four collection types, not just
associative ones. For :+
and :r
, a new value is also required.
The following options are supported in the option map of the last argument:
:algo
chooses the diff algorithm. The value can be :a-star
(default) or
:quick
; :a-star
algorithm minimize the size of the resulting editscript,
:quick
algorithm is much faster, but does not producing diff with minimal size.
:str-diff
indicates a desire to perform string diff. It may reduce the
result size for small changes in long strings, but will incur a slight computation
cost. The value is a boolean: true
or false
(default). When enabled, the diff
algorithm will perform string diff if the changes are less than 30 percent of the
string length; otherwise, whole string replacement will be used.
:str-change-limit
, a less than 1.0
and greater than 0.0
double value,
representing percentage (default 0.2
). Only diff string when less than given
percentage is changed, otherwise replace the string.
:vec-timeout
specifies a timeout in milliseconds (default 1000
),
for diffing vectors, as it has O(n^2) running time. When timed-out, a replacement
operation will be used.
Create an editscript to represent the transformations needed to turn a Clojure data structure `a` into another Clojure data structure `b`. This function accepts any nested Clojure data structures. In Clojure, those implement `IPersistentVector`, `IPersistentMap`, `IPersistentList`, and `IPersistentSet` will be treated as collections. The same are true for the corresponding deftypes in Clojurescript, such as `PersistentVector`, `PersistentMap`, and so on. Anything else are treated as atomic values. The editscript is represented as a vector of basic operations: add `:+`, delete `:-`, and replace `:r`. Each operation also include a path to the location of the operation, which is similar to the path vector in `update-in`. However, editscript path works for all above four collection types, not just associative ones. For `:+` and `:r`, a new value is also required. The following options are supported in the option map of the last argument: * `:algo` chooses the diff algorithm. The value can be `:a-star` (default) or `:quick`; `:a-star` algorithm minimize the size of the resulting editscript, `:quick` algorithm is much faster, but does not producing diff with minimal size. * `:str-diff` indicates a desire to perform string diff. It may reduce the result size for small changes in long strings, but will incur a slight computation cost. The value is a boolean: `true` or `false` (default). When enabled, the diff algorithm will perform string diff if the changes are less than 30 percent of the string length; otherwise, whole string replacement will be used. * `:str-change-limit`, a less than `1.0` and greater than `0.0` double value, representing percentage (default `0.2`). Only diff string when less than given percentage is changed, otherwise replace the string. * `:vec-timeout` specifies a timeout in milliseconds (default `1000`), for diffing vectors, as it has O(n^2) running time. When timed-out, a replacement operation will be used.
(edit-distance es)
Report the edit distance of the editscript, i.e. number of operations
Report the edit distance of the editscript, i.e. number of operations
(edits->script edits)
Create an EditScript instance from a vector of edits, like those
obtained through calling get-edits
on an EditScript
Create an EditScript instance from a vector of edits, like those obtained through calling `get-edits` on an EditScript
(get-adds-num es)
Report the number of additions in the editscript
Report the number of additions in the editscript
(get-dels-num es)
Report the number of deletes in the editscript
Report the number of deletes in the editscript
(get-edits es)
Report the edits of the editscript as a vector
Report the edits of the editscript as a vector
(get-reps-num es)
Report the edits of replacements in the editscript
Report the edits of replacements in the editscript
(get-size es)
Report the size of the editscript
Report the size of the editscript
(patch a script)
Apply the editscript script
on a
to produce b
, assuming the
script is the results of running (diff a b)
, such that
(= b (patch a (diff a b)))
is true
Apply the editscript `script` on `a` to produce `b`, assuming the script is the results of running `(diff a b)`, such that `(= b (patch a (diff a b)))` is true
(valid-edits? edits)
Check if the given vector represents valid edits that can be turned into an EditScript
Check if the given vector represents valid edits that can be turned into an EditScript
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close