2.4 KiB
2.4 KiB
fzy src/match.c
Metadata
| Field | Value |
|---|---|
| Institute | Molodetz Institute — Research & Retrieval Division |
| Subject | fuzzy-matching-selectors |
| Document type | Source Dossier |
| Tier | 1 |
| Source title | fzy src/match.c |
| Source URL | https://raw.githubusercontent.com/jhawthorn/fzy/master/src/match.c |
| Source publisher / author | jhawthorn (fzy maintainer) |
| Source type | repository |
| Source date (published) | Unknown — not stated |
| Date researched | 2026-10-25 |
| Researched by | tai (agent), model: Claude Sonnet 5, on behalf of retoor |
| Research method | direct page fetch |
| Confidence | Medium |
| Status | Active |
Summary
The C implementation of fzy's matcher. The scoring constants are not in this file (they live in config.h and bonus.h, which were not fetched), but the dynamic-programming recurrences, the prefilter and the length cap logic are.
Key findings
has_matchis a prefilter: for each needle byte it finds the next case-insensitive occurrence in the haystack and advances; it returns 0 when any byte is missing.match()andmatch_positions()return SCORE_MIN when the haystack is longer than MATCH_MAX_LEN or the needle is longer than the haystack.precompute_bonusstarts with last_ch = '/' and sets match_bonus[i] = COMPUTE_BONUS(last_ch, ch): the bonus depends on the preceding character.- Row recurrence: gap_score is SCORE_GAP_TRAILING on the last needle row, else SCORE_GAP_INNER. When needle[i] equals haystack[j]: for i == 0, score = j * SCORE_GAP_LEADING + match_bonus[j]; for i > 0 and j > 0, score = max(prev_M + match_bonus[j], prev_D + SCORE_MATCH_CONSECUTIVE). D[j] = score and M[j] = max(score, M[j-1] + gap_score). Otherwise D[j] = SCORE_MIN and M[j] = M[j-1] + gap_score.
match()returns SCORE_MAX when needle and haystack have the same length; otherwise the last cell of M.
Pros / strengths
Exact, short, readable recurrences; shows the cheap prefilter that makes large candidate lists affordable.
Cons / limitations / caveats
Constants (SCORE_GAP_, SCORE_MATCH_) and MATCH_MAX_LEN are not defined in the fetched file, so no numbers can be quoted from it.
Relevance to tai
The recurrence is the shape of FuzzyMatcher::Subsequence (D = ends in match, M = best prefix). The prefilter idea is covered by the n > m early return.
Changelog
| Date | Change |
|---|---|
| 2026-10-25 | Initial dossier created. |