diff --git a/lua/u/renderer.lua b/lua/u/renderer.lua index 4617372..2da6074 100644 --- a/lua/u/renderer.lua +++ b/lua/u/renderer.lua @@ -434,7 +434,7 @@ function TreeBuilder:tree() return self.nodes end --- @param x `T`[] --- @param y T[] --- @param cost? { of_delete?: fun(x: T): number; of_add?: fun(x: T): number; of_change?: fun(x: T, y: T): number; } ---- @return LevenshteinChange[] +--- @return LevenshteinChange[] The changes, from last (greatest index) to first (smallest index). function H.levenshtein(x, y, cost) -- At the moment, this whole `cost` plumbing is not used. Deletes have the -- same cost as Adds or Changes. I can imagine a future, however, where @@ -474,10 +474,10 @@ function H.levenshtein(x, y, cost) if x[i] == y[j] then dp[i][j] = dp[i - 1][j - 1] -- no cost if items are the same else - local costDelete = dp[i - 1][j] + cost_of_delete_f(x[i]) - local costAdd = dp[i][j - 1] + cost_of_add_f(y[j]) - local costChange = dp[i - 1][j - 1] + cost_of_change_f(x[i], y[j]) - dp[i][j] = math.min(costDelete, costAdd, costChange) + local cost_delete = dp[i - 1][j] + cost_of_delete_f(x[i]) + local cost_add = dp[i][j - 1] + cost_of_add_f(y[j]) + local cost_change = dp[i - 1][j - 1] + cost_of_change_f(x[i], y[j]) + dp[i][j] = math.min(cost_delete, cost_add, cost_change) end end end