Skip to content

Commit 4f99173

Browse files
committed
Add doc comments to public APIs
1 parent 5d54b5a commit 4f99173

6 files changed

Lines changed: 21 additions & 0 deletions

File tree

build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const std = @import("std");
22

3+
/// Configures build artifacts, helper steps, and test/check pipelines.
34
pub fn build(b: *std.Build) void {
45
const target = b.standardTargetOptions(.{});
56
const optimize = b.standardOptimizeOption(.{});

src/main.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub fn bufferedPrint() !void {
1313
try stdout.flush();
1414
}
1515

16+
/// Demo executable entrypoint that parses a tiny document and prints one query result.
1617
pub fn main() !void {
1718
try bufferedPrint();
1819

tools/bench/bench.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fn parseDocForBench(noalias doc: *Document, input: []u8, mode: BenchMode) !void
2525
}
2626
}
2727

28+
/// Runs a built-in synthetic parse/query workload and prints elapsed ns.
2829
pub fn runSynthetic() !void {
2930
const alloc = std.heap.page_allocator;
3031

@@ -51,6 +52,7 @@ pub fn runSynthetic() !void {
5152
std.debug.print("query ns: {d}\n", .{query_end - query_start});
5253
}
5354

55+
/// Benchmarks parse throughput for one fixture and mode; returns total elapsed ns.
5456
pub fn runParseFile(path: []const u8, iterations: usize, mode: BenchMode) !u64 {
5557
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
5658
defer _ = gpa.deinit();
@@ -89,6 +91,7 @@ pub fn runParseFile(path: []const u8, iterations: usize, mode: BenchMode) !u64 {
8991
return @intCast(end - start);
9092
}
9193

94+
/// Benchmarks runtime selector parse cost; returns total elapsed ns.
9295
pub fn runQueryParse(selector: []const u8, iterations: usize) !u64 {
9396
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
9497
defer _ = gpa.deinit();
@@ -108,6 +111,7 @@ pub fn runQueryParse(selector: []const u8, iterations: usize) !u64 {
108111
return @intCast(end - start);
109112
}
110113

114+
/// Benchmarks runtime query execution over a pre-parsed document.
111115
pub fn runQueryMatch(path: []const u8, selector: []const u8, iterations: usize, mode: BenchMode) !u64 {
112116
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
113117
defer _ = gpa.deinit();
@@ -133,6 +137,7 @@ pub fn runQueryMatch(path: []const u8, selector: []const u8, iterations: usize,
133137
return @intCast(end - start);
134138
}
135139

140+
/// Benchmarks cached-selector query execution over a pre-parsed document.
136141
pub fn runQueryCached(path: []const u8, selector: []const u8, iterations: usize, mode: BenchMode) !u64 {
137142
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
138143
defer _ = gpa.deinit();
@@ -163,6 +168,7 @@ pub fn runQueryCached(path: []const u8, selector: []const u8, iterations: usize,
163168
return @intCast(end - start);
164169
}
165170

171+
/// CLI entrypoint for parser/query benchmarking utilities.
166172
pub fn main() !void {
167173
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
168174
defer _ = gpa.deinit();

tools/common.zig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
const std = @import("std");
22

3+
/// Returns true when `path` exists relative to the current working directory.
34
pub fn fileExists(path: []const u8) bool {
45
std.fs.cwd().access(path, .{}) catch return false;
56
return true;
67
}
78

9+
/// Creates `path` and any missing parent directories.
810
pub fn ensureDir(path: []const u8) !void {
911
try std.fs.cwd().makePath(path);
1012
}
1113

14+
/// Renders argv-like tokens as a shell-style debug string.
1215
pub fn joinArgs(alloc: std.mem.Allocator, argv: []const []const u8) ![]u8 {
1316
var out = std.ArrayList(u8).empty;
1417
errdefer out.deinit(alloc);
@@ -26,6 +29,7 @@ pub fn joinArgs(alloc: std.mem.Allocator, argv: []const []const u8) ![]u8 {
2629
return out.toOwnedSlice(alloc);
2730
}
2831

32+
/// Runs a child process inheriting stdio, returning error on non-zero exit.
2933
pub fn runInherit(alloc: std.mem.Allocator, argv: []const []const u8, cwd: ?[]const u8) !void {
3034
const pretty = try joinArgs(alloc, argv);
3135
defer alloc.free(pretty);
@@ -44,6 +48,7 @@ pub fn runInherit(alloc: std.mem.Allocator, argv: []const []const u8, cwd: ?[]co
4448
}
4549
}
4650

51+
/// Runs a child process and returns combined stdout/stderr output.
4752
pub fn runCaptureCombined(alloc: std.mem.Allocator, argv: []const []const u8, cwd: ?[]const u8) ![]u8 {
4853
const res = try std.process.Child.run(.{
4954
.allocator = alloc,
@@ -68,6 +73,7 @@ pub fn runCaptureCombined(alloc: std.mem.Allocator, argv: []const []const u8, cw
6873
return out.toOwnedSlice(alloc);
6974
}
7075

76+
/// Runs a child process and returns trimmed stdout output.
7177
pub fn runCaptureStdout(alloc: std.mem.Allocator, argv: []const []const u8, cwd: ?[]const u8) ![]u8 {
7278
const res = try std.process.Child.run(.{
7379
.allocator = alloc,
@@ -84,6 +90,7 @@ pub fn runCaptureStdout(alloc: std.mem.Allocator, argv: []const []const u8, cwd:
8490
return alloc.dupe(u8, std.mem.trim(u8, res.stdout, " \r\n\t"));
8591
}
8692

93+
/// Parses the last decimal integer token found in `text`.
8794
pub fn parseLastInt(text: []const u8) !u64 {
8895
var i: usize = text.len;
8996
while (i > 0) : (i -= 1) {
@@ -96,6 +103,7 @@ pub fn parseLastInt(text: []const u8) !u64 {
96103
return std.fmt.parseInt(u64, text[start..i], 10);
97104
}
98105

106+
/// Returns median value from `vals` (upper median for even length).
99107
pub fn medianU64(alloc: std.mem.Allocator, vals: []const u64) !u64 {
100108
if (vals.len == 0) return error.EmptyInput;
101109
const copy = try alloc.dupe(u64, vals);
@@ -104,16 +112,19 @@ pub fn medianU64(alloc: std.mem.Allocator, vals: []const u64) !u64 {
104112
return copy[copy.len / 2];
105113
}
106114

115+
/// Writes `bytes` to `path`, truncating any existing file.
107116
pub fn writeFile(path: []const u8, bytes: []const u8) !void {
108117
const file = try std.fs.cwd().createFile(path, .{ .truncate = true });
109118
defer file.close();
110119
try file.writeAll(bytes);
111120
}
112121

122+
/// Reads an entire file into allocator-owned memory.
113123
pub fn readFileAlloc(alloc: std.mem.Allocator, path: []const u8) ![]u8 {
114124
return try std.fs.cwd().readFileAlloc(alloc, path, std.math.maxInt(usize));
115125
}
116126

127+
/// Returns current UNIX timestamp in seconds.
117128
pub fn nowUnix() i64 {
118129
return std.time.timestamp();
119130
}

tools/scripts.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,6 +2630,7 @@ fn usage() void {
26302630
, .{});
26312631
}
26322632

2633+
/// CLI entrypoint for repository maintenance, benchmarking, and conformance tasks.
26332634
pub fn main() !void {
26342635
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
26352636
defer arena.deinit();

tools/suite_runner.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ fn usage() noreturn {
165165
std.process.exit(2);
166166
}
167167

168+
/// CLI entrypoint used by external-suite tooling to execute selector/parser probes.
168169
pub fn main() !void {
169170
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
170171
defer _ = gpa.deinit();

0 commit comments

Comments
 (0)