fuzzy

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package fuzzy ranks completion candidates against a typed pattern. The matcher is the subsequence kind every editor's file picker uses: the pattern's characters must appear in the candidate in order, and the score prefers matches at path-segment and word starts, consecutive runs, and short candidates, so "sre" finds "screen/render.go" ahead of an accidental scatter of the same letters. Matching is case-insensitive; an exact-case hit earns a small bonus.

Everything here is pure and deterministic: same inputs, same order, no clock, no randomness. Ties in Rank break by shorter candidate, then lexically, so the menu never reshuffles between keystrokes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Rank

func Rank(pattern string, candidates []string, limit int, bonus func(string) int) []string

Rank returns the best matches for pattern among candidates, best first, at most limit long. An optional bonus hook adds candidate-specific score (recent picks, pinned entries); nil adds nothing. Order is deterministic: score descending, then shorter candidate, then lexical.

func Score

func Score(pattern, candidate string) (int, bool)

Score reports how well pattern matches candidate, and whether it matches at all. The empty pattern matches everything with score zero. A greedy forward scan keeps the cost linear in the candidate; it can under-score an adversarial alignment, but it never misses a match.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL