16 #ifndef LLVM_ADT_EDIT_DISTANCE_H 17 #define LLVM_ADT_EDIT_DISTANCE_H 44 bool AllowReplacements =
true,
45 unsigned MaxEditDistance = 0) {
61 const unsigned SmallBufferSize = 64;
62 unsigned SmallBuffer[SmallBufferSize];
63 std::unique_ptr<unsigned[]> Allocated;
64 unsigned *Row = SmallBuffer;
65 if (n + 1 > SmallBufferSize) {
66 Row =
new unsigned[n + 1];
70 for (
unsigned i = 1; i <= n; ++i)
75 unsigned BestThisRow = Row[0];
77 unsigned Previous = y - 1;
80 if (AllowReplacements) {
82 Previous + (FromArray[y-1] == ToArray[x-1] ? 0u : 1u),
83 std::min(Row[x-1], Row[x])+1);
86 if (FromArray[y-1] == ToArray[x-1]) Row[x] = Previous;
87 else Row[x] = std::min(Row[x-1], Row[x]) + 1;
90 BestThisRow = std::min(BestThisRow, Row[x]);
93 if (MaxEditDistance && BestThisRow > MaxEditDistance)
94 return MaxEditDistance + 1;
97 unsigned Result = Row[n];
This class represents lattice values for constants.
unsigned ComputeEditDistance(ArrayRef< T > FromArray, ArrayRef< T > ToArray, bool AllowReplacements=true, unsigned MaxEditDistance=0)
Determine the edit distance between two sequences.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
size_t size() const
size - Get the array size.