15 #ifndef LLVM_ADT_EDIT_DISTANCE_H 16 #define LLVM_ADT_EDIT_DISTANCE_H 43 bool AllowReplacements =
true,
44 unsigned MaxEditDistance = 0) {
60 const unsigned SmallBufferSize = 64;
61 unsigned SmallBuffer[SmallBufferSize];
62 std::unique_ptr<unsigned[]> Allocated;
63 unsigned *Row = SmallBuffer;
64 if (n + 1 > SmallBufferSize) {
65 Row =
new unsigned[n + 1];
69 for (
unsigned i = 1; i <= n; ++i)
74 unsigned BestThisRow = Row[0];
76 unsigned Previous = y - 1;
79 if (AllowReplacements) {
81 Previous + (FromArray[y-1] == ToArray[x-1] ? 0u : 1u),
82 std::min(Row[x-1], Row[x])+1);
85 if (FromArray[y-1] == ToArray[x-1]) Row[x] = Previous;
86 else Row[x] = std::min(Row[x-1], Row[x]) + 1;
89 BestThisRow = std::min(BestThisRow, Row[x]);
92 if (MaxEditDistance && BestThisRow > MaxEditDistance)
93 return MaxEditDistance + 1;
96 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.