9 const std::string &
string,
10 std::size_t allowed_errors)
12 const std::size_t layer_offset =
string.size() + 1;
13 for(std::size_t i = 0; i <= allowed_errors; ++i)
15 final_states.push_back(
string.size() + layer_offset * i);
17 for(std::size_t string_index = 0; string_index <
string.size();
20 for(std::size_t error_layer = 0; error_layer <= allowed_errors;
25 error_layer * layer_offset + string_index,
27 error_layer * layer_offset + string_index + 1);
28 if(error_layer < allowed_errors)
32 error_layer * layer_offset + string_index,
33 (error_layer + 1) * layer_offset + string_index);
35 error_layer * layer_offset + string_index,
36 (error_layer + 1) * layer_offset + string_index + 1);
38 error_layer * layer_offset + string_index,
39 (error_layer + 1) * layer_offset + string_index + 1);
43 for(std::size_t error_layer = 0; error_layer < allowed_errors; ++error_layer)
47 error_layer * layer_offset +
string.size(),
48 (error_layer + 1) * layer_offset +
string.size());
57 std::optional<std::size_t>
61 for(
const auto c :
string)
65 for(std::size_t distance = 0; distance <
final_states.size(); ++distance)
levenshtein_automatont(const std::string &string, std::size_t allowed_errors=2)
std::optional< std::size_t > get_edit_distance(const std::string &string) const
bool matches(const std::string &string) const
std::vector< state_labelt > final_states
statet initial_state(state_labelt initial) const
statet next_state(const statet ¤t, const T &input) const
void add_arbitrary_transition(state_labelt from, state_labelt to)
Add a transition from "from" to "to" when any input is consumed This is handled a special case so not...
void add_transition(state_labelt from, T when, state_labelt to)
Add a transition from "from" to "to" exactly when "when" is consumed.
void add_epsilon_transition(state_labelt from, state_labelt to)
Add a transition from "from" to "to" that doesn’t consume input.