summaryrefslogtreecommitdiff
path: root/src/Names.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Names.zig')
-rw-r--r--src/Names.zig19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/Names.zig b/src/Names.zig
index fed63f2e..a3fff314 100644
--- a/src/Names.zig
+++ b/src/Names.zig
@@ -161,7 +161,7 @@ pub fn rescore(n: *Names, gpa: std.mem.Allocator) void {
} else break;
const c = n.cands.items[i];
const key = n.bytes.items[c.start + c.key ..][0..c.key_len];
- const s = if (empty) 0 else match(q, key, n.lower.items[c.start + c.key ..][0..c.key_len], c.base, null, null, null);
+ const s = if (empty) 0 else match(q, key, n.lower.items[c.start + c.key ..][0..c.key_len], c.base, null, null);
if (s) |score| n.hits.append(gpa, .{ .cand = i, .score = score }) catch break;
// The clock every 256 candidates: reading it is not free either.
if (!empty and count % 256 == 255 and pardes.tape.over(started, score_budget_ns)) break;
@@ -187,7 +187,7 @@ pub fn row(n: *const Names, i: usize, marks: []u16, nmarks: *usize) []const u8 {
const q = n.queryText();
if (std.mem.trim(u8, q, " ").len > 0) {
const key = n.bytes.items[c.start + c.key ..][0..c.key_len];
- _ = match(q, key, n.lower.items[c.start + c.key ..][0..c.key_len], c.base, marks, nmarks, &dp_trace);
+ _ = match(q, key, n.lower.items[c.start + c.key ..][0..c.key_len], c.base, marks, nmarks);
for (marks[0..nmarks.*]) |*m| m.* += c.key;
}
return n.bytes.items[c.start..][0..c.len];
@@ -233,8 +233,9 @@ fn bonusAt(text: []const u8, j: usize) i32 {
/// `query`'s score against `text` (`lower` its lowercase copy, its
/// basename from `base`), null if some term of it is not a subsequence of
/// `text`. Terms split on spaces are ANDed; smart case per term. With
-/// `marks`, the bytes matched are written there, ascending.
-pub fn match(query: []const u8, text_in: []const u8, lower_in: []const u8, base: usize, marks: ?[]u16, marks_len: ?*usize, trace: ?[]i32) ?i32 {
+/// `marks`, the bytes matched are written there, ascending (the table they
+/// are backtracked through is `dp_trace`).
+fn match(query: []const u8, text_in: []const u8, lower_in: []const u8, base: usize, marks: ?[]u16, marks_len: ?*usize) ?i32 {
const text = text_in[0..@min(text_in.len, max_text)];
const lower = lower_in[0..text.len];
var total: i32 = 0;
@@ -260,7 +261,7 @@ pub fn match(query: []const u8, text_in: []const u8, lower_in: []const u8, base:
var prev = &dp_rows[0];
var cur = &dp_rows[1];
const width = text.len;
- const keep = if (trace) |t| t.len >= m * width else false;
+ const keep = marks != null;
for (0..m) |i| {
var gapped: i32 = neg; // max over k <= j-2 of D[i-1][k], less the gap to j
for (lo..end) |col| {
@@ -276,7 +277,7 @@ pub fn match(query: []const u8, text_in: []const u8, lower_in: []const u8, base:
}
}
cur[col] = best;
- if (keep) trace.?[i * width + col] = best;
+ if (keep) dp_trace[i * width + col] = best;
}
const t = prev;
prev = cur;
@@ -291,9 +292,9 @@ pub fn match(query: []const u8, text_in: []const u8, lower_in: []const u8, base:
if (best <= neg) return null;
total += best;
// Back from the best end, the place each character was matched at.
- if (keep and marks != null) {
+ if (keep) {
const out = marks.?;
- const t = trace.?;
+ const t = &dp_trace;
var i = m;
var col = at;
while (i > 0) {
@@ -345,7 +346,7 @@ fn topFor(q: []const u8) []const u8 {
var best_score: i32 = std.math.minInt(i32);
for (test_paths) |path| {
var low: [256]u8 = undefined;
- const s = match(q, path, std.ascii.lowerString(&low, path), baseOf(path), null, null, null) orelse continue;
+ const s = match(q, path, std.ascii.lowerString(&low, path), baseOf(path), null, null) orelse continue;
if (s > best_score or (s == best_score and path.len < best.?.len)) {
best = path;
best_score = s;