userver: userver/utils/distances.hpp File Reference
Loading...
Searching...
No Matches
distances.hpp File Reference

Detailed Description

Distances between strings and nearest string suggestions.

Definition in file distances.hpp.

Go to the source code of this file.

#include <optional>
#include <string>
#include <string_view>
#include <type_traits>

Namespaces

namespace  utils
 Utilities.
 

Functions

std::size_t utils::GetLevenshteinDistance (std::string_view view1, std::string_view view2)
 Returns the Levenshtein distance between two strings.
 
std::size_t utils::GetDamerauLevenshteinDistance (std::string_view view1, std::string_view view2)
 Returns the Damerau-Levenshtein distance between two strings.
 
template<typename StringViews , typename DistanceFunc = std::size_t (*)(std::string_view, std::string_view)>
std::optional< std::string_view > utils::GetNearestString (const StringViews &strings, std::string_view key, std::size_t max_distance, DistanceFunc distance_func=&utils::GetLevenshteinDistance)
 Returns a nearest string for a key from a bunch of strings.
 
template<typename StringViews >
std::string utils::SuggestNearestName (const StringViews &strings, std::string_view key)
 Returns a suggestion for a key.