16#ifndef LLVM_ADT_EDIT_DISTANCE_H
17#define LLVM_ADT_EDIT_DISTANCE_H
44template <
typename T,
typename Functor>
46 Functor Map,
bool AllowReplacements =
true,
47 unsigned MaxEditDistance = 0) {
63 if (MaxEditDistance) {
68 if (AbsDiff > MaxEditDistance)
69 return MaxEditDistance + 1;
73 for (
unsigned i = 1; i < Row.size(); ++i)
78 unsigned BestThisRow = Row[0];
80 unsigned Previous = y - 1;
81 const auto &CurItem = Map(FromArray[y - 1]);
84 if (AllowReplacements) {
85 Row[x] = std::min(Previous + (CurItem == Map(ToArray[x - 1]) ? 0u : 1u),
86 std::min(Row[x - 1], Row[x]) + 1);
89 if (CurItem == Map(ToArray[x - 1]))
91 else Row[x] = std::min(Row[x-1], Row[x]) + 1;
94 BestThisRow = std::min(BestThisRow, Row[x]);
97 if (MaxEditDistance && BestThisRow > MaxEditDistance)
98 return MaxEditDistance + 1;
101 unsigned Result = Row[n];
107 bool AllowReplacements =
true,
108 unsigned MaxEditDistance = 0) {
110 FromArray, ToArray, [](
const T &
X) ->
const T & {
return X; },
111 AllowReplacements, MaxEditDistance);
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This is an optimization pass for GlobalISel generic memory operations.
unsigned ComputeEditDistance(ArrayRef< T > FromArray, ArrayRef< T > ToArray, bool AllowReplacements=true, unsigned MaxEditDistance=0)
unsigned ComputeMappedEditDistance(ArrayRef< T > FromArray, ArrayRef< T > ToArray, Functor Map, bool AllowReplacements=true, unsigned MaxEditDistance=0)
Determine the edit distance between two sequences.