| 452 | } |
| 453 | |
| 454 | int ChangesManager::levenshteinDistance(const QString &s1, const QString &s2) const |
| 455 | { |
| 456 | const int len1 = s1.length(); |
| 457 | const int len2 = s2.length(); |
| 458 | |
| 459 | const int MAX_LENGTH = 10000; |
| 460 | if (len1 > MAX_LENGTH || len2 > MAX_LENGTH) { |
| 461 | return qAbs(len1 - len2) + qMin(len1, len2) / 2; |
| 462 | } |
| 463 | |
| 464 | QVector<QVector<int>> d(len1 + 1, QVector<int>(len2 + 1)); |
| 465 | |
| 466 | for (int i = 0; i <= len1; ++i) { |
| 467 | d[i][0] = i; |
| 468 | } |
| 469 | for (int j = 0; j <= len2; ++j) { |
| 470 | d[0][j] = j; |
| 471 | } |
| 472 | |
| 473 | for (int i = 1; i <= len1; ++i) { |
| 474 | for (int j = 1; j <= len2; ++j) { |
| 475 | int cost = (s1[i - 1] == s2[j - 1]) ? 0 : 1; |
| 476 | d[i][j] = std::min({ |
| 477 | d[i - 1][j] + 1, |
| 478 | d[i][j - 1] + 1, |
| 479 | d[i - 1][j - 1] + cost |
| 480 | }); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | return d[len1][len2]; |
| 485 | } |
| 486 | |
| 487 | QString ChangesManager::findBestMatchLineBased( |
| 488 | const QString &fileContent, |
nothing calls this directly
no outgoing calls
no test coverage detected