| ... | ... | @@ -1,5 +1,4 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | | const range = @import("range").range; |
| 3 | 2 | |
| 4 | 3 | // // the naïve recursive implementation |
| 5 | 4 | // pub fn leven(comptime T: type, a: []const T, b: []const T) usize { |
| ... | ... | @@ -53,17 +52,17 @@ pub fn leven(comptime T: type, alloc: std.mem.Allocator, a: []const T, b: []cons |
| 53 | 52 | const array = try alloc.alloc(usize, ll); |
| 54 | 53 | defer alloc.free(array); |
| 55 | 54 | |
| 56 | | for (range(ll), 0..) |_, i| { |
| 55 | for (0..ll) |i| { |
| 57 | 56 | charCodeCache[i] = left[start + i]; |
| 58 | 57 | array[i] = i + 1; |
| 59 | 58 | } |
| 60 | 59 | |
| 61 | | for (range(rl), 0..) |_, j| { |
| 60 | for (0..rl) |j| { |
| 62 | 61 | const bCharCode = right[start + j]; |
| 63 | 62 | var temp = j; |
| 64 | 63 | result = j + 1; |
| 65 | 64 | |
| 66 | | for (range(ll), 0..) |_, i| { |
| 65 | for (0..ll) |i| { |
| 67 | 66 | const temp2 = if (bCharCode == charCodeCache[i]) temp else temp + 1; |
| 68 | 67 | temp = array[i]; |
| 69 | 68 | array[i] = if (temp > result) (if (temp2 > result) result + 1 else temp2) else (if (temp2 > temp) temp + 1 else temp2); |