Skip to content

Commit

Permalink
use std::swap instead of C-style variable swap
Browse files Browse the repository at this point in the history
  • Loading branch information
larsmans committed Nov 18, 2013
1 parent c1db71d commit e42c12f
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions levenshtein_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,8 @@ static unsigned levenshtein(Char const *a, size_t m, Char const *b, size_t n)
{
// Swap a and b if necessary to ensure m <= n.
if (m > n) {
Char const *p;
size_t t;

p = a;
a = b;
b = p;

t = m;
m = n;
n = t;
std::swap(a, b);
std::swap(m, n);
}

// Skip common prefix.
Expand All @@ -58,16 +50,13 @@ static unsigned levenshtein(Char const *a, size_t m, Char const *b, size_t n)
}

std::vector<unsigned> tab((m + 1) * 2);

unsigned *cur = tab.data(), *prev = tab.data() + m + 1;

for (size_t i = 0; i <= m; i++) {
cur[i] = i;
}
for (size_t j = 1; j <= n; j++) {
unsigned *t = cur;
cur = prev;
prev = t;
std::swap(cur, prev);

cur[0] = j;

Expand Down

0 comments on commit e42c12f

Please sign in to comment.