branch: externals/hotfuzz
commit 6899be957694a273eb71c21c3eae649d877c9e0b
Author: Axel Forsman <[email protected]>
Commit: Axel Forsman <[email protected]>

    Ignore trailing gap start
    
    Closes #19
---
 hotfuzz-module.c | 6 +++---
 hotfuzz.el       | 8 ++++----
 test/tests.el    | 2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hotfuzz-module.c b/hotfuzz-module.c
index b1fb91d2c6..04eeb64b92 100644
--- a/hotfuzz-module.c
+++ b/hotfuzz-module.c
@@ -56,12 +56,12 @@ static int char_bonus(char prev, char ch) {
 }
 
 static void match_row(struct Str a, struct Str b, int *bonuses, unsigned i, 
int *c, int *d) {
-       int g = 100, h = 5;
+       int g = 100, h = 10;
        size_t m = b.len;
-       int oldc, s = i ? g + h * i : 0;
+       int oldc, s = i ? g + 5 * i : 0;
        for (size_t j = 0; j < m; ++j, s = oldc) {
                oldc = c[j];
-               d[j] = MIN(d[j], oldc + g) + (j == m - 1 ? h : 2 * h);
+               d[j] = MIN(d[j], oldc + (j < m - 1 ? g : 0)) + h;
                c[j] = a.b[i] == b.b[j] ? MIN(d[j], s - bonuses[i]) : d[j];
        }
 }
diff --git a/hotfuzz.el b/hotfuzz.el
index fd0a8097e8..5db7888aff 100644
--- a/hotfuzz.el
+++ b/hotfuzz.el
@@ -75,16 +75,16 @@ into NC/ND, using the costs for row I-1 in PC/PD. The 
vectors NC/PC
 and ND/PD respectively may alias."
   (cl-loop
    with m = (length b)
-   and g = 100 and h = 5 ; Every k-symbol gap is penalized by g+hk
+   and g = 100 and h = 10 ; Every k-symbol gap is penalized by g+hk
    ;; s threads the old value C[i-1][j-1] throughout the loop
-   for j below m and s = (if (zerop i) 0 (+ g (* h i))) then oldc
+   for j below m and s = (if (zerop i) 0 (+ g (* 5 i))) then oldc
    for oldc = (aref pc j) do
    ;; Either extend optimal conversion of (i) Aᵢ₋₁ to Bⱼ₋₁, by
    ;; matching bⱼ (C[i-1,j-1]-bonus); or (ii) Aᵢ₋₁ to Bⱼ, by deleting
    ;; aᵢ and opening a new gap (C[i-1,j]+g+h) or enlarging the
    ;; previous gap (D[i-1,j]+h).
-   (aset nc j (min (aset nd j (+ (min (aref pd j) (+ oldc g))
-                                 (if (= j (1- m)) h (* 2 h))))
+   (aset nc j (min (aset nd j (+ h (min (+ oldc (if (< j (1- m)) g 0))
+                                        (aref pd j))))
                    (if (char-equal (aref a i) (aref b j))
                        (- s (aref hotfuzz--bonus i))
                      most-positive-fixnum)))))
diff --git a/test/tests.el b/test/tests.el
index 8c19eda650..2fb3f35b73 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -29,7 +29,7 @@
 
 (ert-deftest hotfuzz-tighter-match-cost-test ()
   "Test that matches spanning fewer characters are better."
-  (should (< (hotfuzz--cost "ab" "xaxbxx") (hotfuzz--cost "ab" "xaxxbx"))))
+  (should (< (hotfuzz--cost "ab" "xxaxbx") (hotfuzz--cost "ab" "xaxxbx"))))
 
 ;;; Highlighting tests
 

Reply via email to