Skip to content

Commit b4921f5

Browse files
committed
0.6.5
1 parent 83ce83f commit b4921f5

File tree

7 files changed

+104
-187
lines changed

7 files changed

+104
-187
lines changed

CHANGELOG.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
11
# Change Log
22

3+
## [0.6.5] - 2025-01-24
4+
### Added
5+
- `data-nodes` to return the number of nodes of a piece of data.
6+
- `change-ratio` to return an approximation of an editscript's ratio of change
7+
in term of the original data.
8+
39
## [0.6.4] - 2024-09-24
4-
## Improved
10+
### Improved
511
- Fix boxed math warning. [thx @tonsky]
612
- Update deps
713

814
## [0.6.3] - 2023-03-14
9-
## Improved
15+
### Improved
1016
- Simplify equality test for A* algorithm, increasing diff speed up to 60% for
1117
some data sets.
1218

1319
## [0.6.2] - 2022-08-25
14-
## Fixed
20+
### Fixed
1521
- A couple of typos in code and documentation.
1622

1723
## [0.6.1] - 2022-08-24
18-
## Changed
24+
### Changed
1925
- **Breaking** Change `:str-diff?` option for `diff` to `:str-diff`, whose value
2026
could be `:none` (default, no diff inside string), `:line` (diff by line),
2127
`:word` (diff by word) or `:character` (diff by character, original string
2228
diff, very expensive).
23-
## Added
29+
### Added
2430
- `:vec-timeout` option for `diff`, to specify a timeout in milliseconds
2531
(default 1000), for it is sometimes too expensive to diff vectors. It is
2632
O(n^2), after all. When timed-out, a replacement will be used.
2733
- `:str-change-limit` option for `diff`, a less than `1.0` and greater than
2834
`0.0` double, representing percentage (default `0.2`). Only diff string when
2935
less than given percentage is changed, otherwise replace the string. Because
3036
string diff is expensive, it may be cheaper to replace the whole string.
31-
## Improved
37+
### Improved
3238
- Speed up string diff by coercing into vector first.
3339
- Bump Clojure version
3440

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "clj-editscript",
3-
"version": "0.6.4",
3+
"version": "0.6.5",
44
"license": "EPL-1.0",
55
"homepage": "https://github.com/juji-io/editscript",
66
"repository": {

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject juji/editscript "0.6.4"
1+
(defproject juji/editscript "0.6.5"
22
:description "A diff library for Clojure/ClojureScript data structures"
33
:url "https://github.com/juji-io/editscript"
44
:lein-release {:deploy-via :clojars}

src/editscript/core.cljc

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
(ns editscript.core
1212
(:require [editscript.edit :as e]
1313
[editscript.patch :as p]
14-
[editscript.util.common :as c]
14+
[editscript.util.index :as i]
1515
[editscript.diff.quick :as q]
1616
[editscript.diff.a-star :as a])
1717
#?(:clj (:import [editscript.edit EditScript]
@@ -113,6 +113,29 @@ operations"}
113113
obtained through calling `get-edits` on an EditScript"}
114114
edits->script e/edits->script)
115115

116-
117-
;; (diff (MapEntry/create 1 (MapEntry/create 2 (MapEntry/create 3 4)))
118-
;; (MapEntry/create 1 (MapEntry/create 2 (MapEntry/create 3 "ok"))))
116+
(defn data-nodes
117+
"Return the number of nodes of a piece of data."
118+
[data]
119+
(i/get-size (i/index data)))
120+
121+
(defn- get-data
122+
[data path]
123+
(loop [[f & r] path
124+
v data]
125+
(let [c (p/vget v f)]
126+
(if r
127+
(recur r c)
128+
c))))
129+
130+
(defn change-ratio
131+
"Return an approximation of the ratio of changes of an editscript, a double"
132+
[origin editscript]
133+
(double
134+
(/ (reduce
135+
(fn [^long sum [path op v]]
136+
(+ sum (case op
137+
(:r :+) (data-nodes v)
138+
:s 1
139+
:- (data-nodes (get-data origin path)))))
140+
0 (get-edits editscript))
141+
(data-nodes origin))))

0 commit comments

Comments
 (0)