Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fuzzy find without sorting #22

Merged
merged 1 commit into from
May 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion fuzzy.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,36 @@ The following types of matches apply a bonus:

Penalties are applied for every character in the search string that wasn't matched and all leading
characters upto the first match.

Results are sorted by best match.
*/
func Find(pattern string, data []string) Matches {
return FindFrom(pattern, stringSource(data))
}

/*
FindNoSort is an alternative Find implementation that does not sort
the results in the end.
*/
func FindNoSort(pattern string, data []string) Matches {
return FindFromNoSort(pattern, stringSource(data))
}

/*
FindFrom is an alternative implementation of Find using a Source
instead of a list of strings.
*/
func FindFrom(pattern string, data Source) Matches {
matches := FindFromNoSort(pattern, data)
sort.Stable(matches)
return matches
}

/*
FindFromNoSort is an alternative FindFrom implementation that does
not sort results in the end.
*/
func FindFromNoSort(pattern string, data Source) Matches {
if len(pattern) == 0 {
return nil
}
Expand Down Expand Up @@ -181,7 +201,6 @@ func FindFrom(pattern string, data Source) Matches {
matchedIndexes = match.MatchedIndexes[:0] // Recycle match index slice
}
}
sort.Stable(matches)
return matches
}

Expand Down