Liking cljdoc? Tell your friends :D

clj-diff.core

Diff, patch and related functions for Clojure sequences.

Diff, patch and related functions for Clojure sequences.
raw docstring

diffclj

(diff a b)

Create the edit script for transforming sequance a into sequence b. An edit script is a map with keys :+ and :- for additions and deletions. Additions are represented as a sequence of vectors. The first item in each vector is the index where the rest of the items in the vector are to be inserted. For example [3 b c] means to insert b an c after whatever is in index 3. Deletions are represented as a sequence of indexes to delete.

For example: the diff of 'abcabba' and 'cbabac' would generate the edit script below.

{:+ [[2 b] [6 c]], :- [0 1 5]}

An index of -1 may appear in additions and is a special case which means to add the elements at the beginning of the sequence.

Create the edit script for transforming sequance a into sequence b.
An edit script is a map with keys :+ and :- for additions and deletions.
Additions are represented as a sequence of vectors. The first item in each
vector is the index where the rest of the items in the vector are to be
inserted. For example [3 b c] means to insert b an c after whatever is
in index 3. Deletions are represented as a sequence of indexes to delete.

For example: the diff of 'abcabba' and 'cbabac' would generate the edit
script below.

    {:+ [[2 b] [6 c]], :- [0 1 5]}

An index of -1 may appear in additions and is a special case which means to
add the elements at the beginning of the sequence.
sourceraw docstring

edit-distanceclj

(edit-distance edit-script)
(edit-distance a b)

Returns the edit distance between the two passed sequences. May also be passed an edit script. The edit distance is the minimum number of insertions and deletions required to transform one sequence into another.

Returns the edit distance between the two passed sequences. May also be
passed an edit script. The edit distance is the minimum number of insertions
and deletions required to transform one sequence into another.
sourceraw docstring

levenshtein-distanceclj

(levenshtein-distance edit-script)
(levenshtein-distance a b)

Returns the Levenshtein distance between two sequences. May either be passed the two sequences or a diff of the two sequences.

From Wikipedia: The Levenshtein distance between two strings is the minimum number of edits needed to transform one string into the other, with the allowable edit operations being insertion, deletion and substitution of a single character.

This function works not only with strings but with any Clojure sequence.

Warning! Technically this function is estimating the Levenshtein distance from a computed diff. Most of the time, it is the same as the real Levenshtein distance but in same cases it may be larger. The reason for this is that there may be multiple paths through an edit graph with the same edit distance but with differing Levenshtein distance. A future improvement to the diff algorithm whould be to find all paths and prefer the one with the minimum Levenshtein distance.

Returns the Levenshtein distance between two sequences. May either be passed
the two sequences or a diff of the two sequences.

From [Wikipedia](http://en.wikipedia.org/wiki/Levenshtein_distance):
The Levenshtein distance between two strings is the minimum number of edits
needed to transform one string into the other, with the allowable edit
operations being insertion, deletion and substitution of a single character.

This function works not only with strings but with any Clojure sequence.

Warning! Technically this function is estimating the Levenshtein distance
from a computed diff. Most of the time, it is the same as the real Levenshtein
distance but in same cases it may be larger. The reason for this is that
there may be multiple paths through an edit graph with the same edit
distance but with differing Levenshtein distance. A future improvement to
the diff algorithm whould be to find all paths and prefer the one with the
minimum Levenshtein distance.
sourceraw docstring

longest-common-subseqclj

(longest-common-subseq a b)
source

patchcljmultimethod

(patch s edit-script)

Use the instructions in the edit script to transform the sequence s into a new sequence. If the edit script was created by using diff on a and b then patch will use the edit script to transform a into b.

(diff a b) -> x, (patch a x) -> b.

Use the instructions in the edit script to transform the sequence s into
a new sequence. If the edit script was created by using diff on a and b then
patch will use the edit script to transform a into b.

(diff a b) -> x, (patch a x) -> b.
sourceraw docstring

patch*clj

(patch* s edit-script)
source

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close