style: adopt TigerStyle across src/; add docs/TIGER_STYLE.md
Wrap signatures and long expressions to the 100-column limit and make every file zig fmt clean. Semantics-preserving throughout: ignoring whitespace and the trailing commas that wrapping introduces, every file here is byte-identical to its predecessor, and the one apparent exception is a warning string split with `++`, which concatenates at comptime to the same bytes. src/index.zig and src/commands.zig are reformatted in the commits that follow, because their reformat is interleaved with in-flight changes to them and separating the two would need the reformat re-derived rather than moved.
This commit is contained in:
@@ -16,7 +16,15 @@ fn doc_of(gpa: std.mem.Allocator, pairs: []const bson.Pair) ![]u8 {
|
||||
|
||||
const Fact = struct { a: i32, b: i32 };
|
||||
|
||||
fn check_range(gpa: std.mem.Allocator, ix: *const index.Index, prefix: bson.Value, lo: ?bson.Value, hi: ?bson.Value, facts: []const Fact, alive: []const bool) !void {
|
||||
fn check_range(
|
||||
gpa: std.mem.Allocator,
|
||||
ix: *const index.Index,
|
||||
prefix: bson.Value,
|
||||
lo: ?bson.Value,
|
||||
hi: ?bson.Value,
|
||||
facts: []const Fact,
|
||||
alive: []const bool,
|
||||
) !void {
|
||||
var out: std.ArrayListUnmanaged([]const u8) = .empty;
|
||||
defer out.deinit(gpa);
|
||||
try ix.lookup_range(gpa, &.{prefix}, lo, true, hi, false, &out);
|
||||
@@ -29,7 +37,13 @@ fn check_range(gpa: std.mem.Allocator, ix: *const index.Index, prefix: bson.Valu
|
||||
expected += 1;
|
||||
}
|
||||
if (out.items.len != expected) {
|
||||
std.debug.print("MISMATCH: prefix={d} lo={?d} hi={?d}: got {d}, want {d}\n", .{ prefix.int32, if (lo) |l| l.int32 else null, if (hi) |h| h.int32 else null, out.items.len, expected });
|
||||
std.debug.print("MISMATCH: prefix={d} lo={?d} hi={?d}: got {d}, want {d}\n", .{
|
||||
prefix.int32,
|
||||
if (lo) |l| l.int32 else null,
|
||||
if (hi) |h| h.int32 else null,
|
||||
out.items.len,
|
||||
expected,
|
||||
});
|
||||
std.process.exit(1);
|
||||
}
|
||||
}
|
||||
@@ -61,7 +75,12 @@ pub fn main() !void {
|
||||
try ix.append_doc_entries(gpa, d, id);
|
||||
}
|
||||
_ = try ix.finish_bulk(gpa, false);
|
||||
std.debug.print("bulk: count={d} leaves={d} depth={d} nodes={d}\n", .{ ix.count(), ix.leaf_count, ix.depth, ix.nodes.items.len });
|
||||
std.debug.print("bulk: count={d} leaves={d} depth={d} nodes={d}\n", .{
|
||||
ix.count(),
|
||||
ix.leaf_count,
|
||||
ix.depth,
|
||||
ix.nodes.items.len,
|
||||
});
|
||||
if (ix.count() != N) return error.BadCount;
|
||||
|
||||
// Random range checks against brute force.
|
||||
@@ -88,7 +107,12 @@ pub fn main() !void {
|
||||
const d = try doc_of(gpa, &pairs);
|
||||
_ = try ix.add_doc(gpa, d, id, false);
|
||||
}
|
||||
std.debug.print("after inserts: count={d} leaves={d} depth={d} nodes={d}\n", .{ ix.count(), ix.leaf_count, ix.depth, ix.nodes.items.len });
|
||||
std.debug.print("after inserts: count={d} leaves={d} depth={d} nodes={d}\n", .{
|
||||
ix.count(),
|
||||
ix.leaf_count,
|
||||
ix.depth,
|
||||
ix.nodes.items.len,
|
||||
});
|
||||
if (ix.count() != N + M) return error.BadCount;
|
||||
for (0..500) |_| {
|
||||
const a = rand.intRangeAtMost(i32, 0, 99);
|
||||
@@ -113,7 +137,12 @@ pub fn main() !void {
|
||||
ix.remove_doc(gpa, d, ids.items[i]);
|
||||
alive.items[i] = false;
|
||||
}
|
||||
std.debug.print("after deletes: count={d} leaves={d} depth={d} nodes={d}\n", .{ ix.count(), ix.leaf_count, ix.depth, ix.nodes.items.len });
|
||||
std.debug.print("after deletes: count={d} leaves={d} depth={d} nodes={d}\n", .{
|
||||
ix.count(),
|
||||
ix.leaf_count,
|
||||
ix.depth,
|
||||
ix.nodes.items.len,
|
||||
});
|
||||
if (ix.count() != (N + M) - (N + M) / 3 - 1) return error.BadCount;
|
||||
for (0..500) |_| {
|
||||
const a = rand.intRangeAtMost(i32, 0, 99);
|
||||
@@ -131,9 +160,15 @@ pub fn main() !void {
|
||||
defer out.deinit(gpa);
|
||||
try ix.lookup_eq(gpa, &.{.{ .int32 = a }}, &out);
|
||||
var expected: usize = 0;
|
||||
for (facts.items, 0..) |f, fi| { if (alive.items[fi] and f.a == a) expected += 1; }
|
||||
for (facts.items, 0..) |f, fi| {
|
||||
if (alive.items[fi] and f.a == a) expected += 1;
|
||||
}
|
||||
if (out.items.len != expected) {
|
||||
std.debug.print("EQ MISMATCH a={d}: got {d} want {d}\n", .{ a, out.items.len, expected });
|
||||
std.debug.print("EQ MISMATCH a={d}: got {d} want {d}\n", .{
|
||||
a,
|
||||
out.items.len,
|
||||
expected,
|
||||
});
|
||||
return error.BadCount;
|
||||
}
|
||||
}
|
||||
@@ -154,11 +189,19 @@ pub fn main() !void {
|
||||
ix.remove_doc(gpa, d, ids.items[i]);
|
||||
remaining -= 1;
|
||||
if (ix.count() != remaining) {
|
||||
std.debug.print("COUNT MISMATCH during drain: {d} != {d}\n", .{ ix.count(), remaining });
|
||||
std.debug.print("COUNT MISMATCH during drain: {d} != {d}\n", .{
|
||||
ix.count(),
|
||||
remaining,
|
||||
});
|
||||
return error.BadCount;
|
||||
}
|
||||
}
|
||||
std.debug.print("after full drain: count={d} leaves={d} depth={d} nodes={d}\n", .{ ix.count(), ix.leaf_count, ix.depth, ix.nodes.items.len });
|
||||
std.debug.print("after full drain: count={d} leaves={d} depth={d} nodes={d}\n", .{
|
||||
ix.count(),
|
||||
ix.leaf_count,
|
||||
ix.depth,
|
||||
ix.nodes.items.len,
|
||||
});
|
||||
if (ix.count() != 0) return error.BadCount;
|
||||
// The drained tree still accepts and finds entries.
|
||||
pairs[0] = .{ .key = "a", .value = .{ .int32 = 7 } };
|
||||
|
||||
Reference in New Issue
Block a user