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