strsim

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package strsim provides string similarity functions for fuzzy matching.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindSimilar

func FindSimilar(target string, candidates []string, maxResults int, maxDistance int) []string

FindSimilar returns strings from candidates that are similar to the target string, using Levenshtein distance for fuzzy matching. Results are sorted by similarity (most similar first) and limited to maxResults.

The maxDistance parameter controls how different a candidate can be from the target. If maxDistance <= 0, a default threshold of max(len(target)/2, 2) is used.

Comparison is case-insensitive.

func LevenshteinDistance

func LevenshteinDistance(a, b string) int

LevenshteinDistance calculates the minimum number of single-character edits (insertions, deletions, or substitutions) required to transform string a into string b.

This is a dynamic programming algorithm that builds a matrix where each cell [i][j] represents the edit distance between the first i characters of a and the first j characters of b.

Time complexity: O(len(a) * len(b)) Space complexity: O(len(a) * len(b))

Types

This section is empty.

Jump to

Keyboard shortcuts

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