levenshtein

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package levenshtein provides edit distance calculation and typo suggestions for commands and flags.

Performance & Allocation Invariant: ASCII string comparisons use a dedicated byte-based algorithm operating directly on string headers without converting to []byte, avoiding string-to-byte conversion allocations. For words <= 32 characters, stack arrays are used to eliminate heap allocations entirely. Do NOT unify distanceBytes and distanceRunes into a generic slice function; converting strings to []byte inside Suggest loops introduces heap allocations on every candidate comparison.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Distance

func Distance(source, target string) int

Distance computes the Levenshtein edit distance between source and target, measured in Unicode code points. ASCII inputs take a byte-based fast path; non-ASCII inputs are compared rune-by-rune.

func Suggest

func Suggest(input string, candidates []string, maxDistance int) string

Suggest finds the best matching candidate for input where the case-insensitive edit distance is strictly less than maxDistance. If maxDistance <= 0, a default threshold of 3 is used.

Types

This section is empty.

Jump to

Keyboard shortcuts

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