0.6.2
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
src
util
levenshtein.h
Go to the documentation of this file.
1
/**
2
* @file src/util/levenshtein.h
3
*
4
* Copyright (c) 2021-2025 Bartek Kryza <bkryza@gmail.com>
5
*
6
* Licensed under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
9
*
10
* http://www.apache.org/licenses/LICENSE-2.0
11
*
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
17
*/
18
#pragma once
19
20
#include <stdexcept>
21
22
#include <algorithm>
23
#include <string>
24
#include <vector>
25
26
namespace
clanguml::util
{
27
28
/**
29
* @brief Compute the Levenshtein distance between two strings.
30
*
31
* @param left First string
32
* @param right Second string
33
* @return Calculated Levenshtein distance
34
*/
35
size_t
levenshtein_distance
(
const
std::string &left,
const
std::string &right);
36
37
/**
38
* @brief Find most similar strings in collection
39
*
40
* Returns at most three strings from `items` that are closest to `pattern`
41
* based on Levenshtein distance.
42
*
43
* @param collection Input collection
44
* @param pattern Pattern to match against items in collection
45
* @return List of most similar items from collection
46
*/
47
48
std::vector<std::string>
get_approximate_matches
(
49
const
std::vector<std::string> &collection,
const
std::string &pattern,
50
int
max_results = 3);
51
52
}
// namespace clanguml::util
Copyright © 2022-present
Bartek Kryza
Generated by
1.9.7