Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add performance tests for levenshtein distance in preparation for att…
…empting to implement a fast algorithm.
- Loading branch information
1 parent
60ebef8
commit eca2adf
Showing
4 changed files
with
56 additions
and
70 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
(ns clj-diff.ld | |||
"Fast implementation of Levenshtein Distance." | |||
(:require [clj-diff [optimizations :as opt]])) | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
(ns clj-diff.other-ld | |||
"Other Levenshtein Disitance functions for use as a comparison.") | |||
|
|||
(defn- new-row | |||
[prev-row row-elem t] | |||
(reduce (fn [row [d-1 d e]] | |||
(conj row | |||
(if (= row-elem e) | |||
d-1 | |||
(inc (min (peek row) d d-1))))) | |||
[(inc (first prev-row))] | |||
(map vector prev-row (next prev-row) t))) | |||
|
|||
(defn laurent-levenshtein | |||
"Very compact implementation from Laurent PETIT." | |||
[s t] | |||
(peek (reduce (fn [prev-row s-elem] | |||
(new-row prev-row s-elem t)) | |||
(range (inc (count t))) | |||
s))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters