a port of dtolnay/dissimilar text diffing library to zig. includes semantic cleanups. based on google's diff match patch.
- reduced memory footprint, limited allocations
- fast diffing, maybe for use in zls
a simple diffing utility that can be run from the command line:
$ zig build run -- <file_a> <file_b>
$ zig build && zig-out/bin/diffit <file_a> <file_b>
this shows ansi colored diffs.
$ zig run -lc -OReleaseFast src/bench.zig -- <file_a> <file_b> <iterations>
$ zig run -lc -OReleaseFast src/bench.zig -- /tmp/dissimilar/benches/document1.txt /tmp/dissimilar/benches/document2.txt 10
took 1.363s for 10 diffs
test {
const diff = @import("lib.zig");
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
const aalloc = arena.allocator();
// 'catch return' just allows test to pass
const file_a = std.fs.cwd().openFile("/path/to/file_a", .{}) catch return;
const file_b = std.fs.cwd().openFile("/path/to/file_b", .{}) catch return;
const doc_a = try file_a.readToEndAlloc(aalloc, std.math.maxInt(u32));
const doc_b = try file_b.readToEndAlloc(aalloc, std.math.maxInt(u32));
var chunks = try diff.diff(aalloc, doc_a, doc_b);
defer chunks.deinit(aalloc);
}
- inspired by tomhoule/zig-diff
- ported from dtolnay/dissimilar
- google diff match patch
- Myers' diff algorithm
- semantic cleanups