Skip to content
pi-c Documentation
Login

Documentation

/* Fuzzy matching, ported from Pi (reference/pi/packages/tui/src/fuzzy.ts)
 * so filtering ranks as Pi's does: the model picker and the slash-command
 * menu (fuzzy.c). */
#ifndef PIC_TUI_FUZZY_H
#define PIC_TUI_FUZZY_H

#include <stddef.h>

/* Pi's fuzzyMatch: whether QUERY matches TEXT and its score (lower is a
 * better match, as in Pi). */
int tui_fuzzy_match(const char *query, const char *text, double *score);

/* Pi's fuzzyFilter over N texts: writes the indexes of the matching texts
 * to order[] (capacity n) best first, ties in input order, and returns how
 * many matched. An empty or all-space query matches everything in input
 * order. */
size_t tui_fuzzy_filter(const char *query, const char *const *texts, size_t n, size_t *order);

/* The edit distance between A and B, case folded: insertions, deletions, substitutions and a swap
 * of two neighbours each cost 1 (optimal string alignment). For "did you mean". */
int tui_edit_distance(const char *a, const char *b);

#endif