Detailed explanation about Damerau Levenshtein Distance algorithm?
The algorithm is based on dynamic programming. It computes a table $d[i,j]$ which stores the edit distance between $a_1\ldots a_i$ and $b_1\ldots b_j$. Although you only really need $i$ to range from $0$ to $\mathrm{length}(a)$ and $j$ to range from $0$ to $\mathrm{length}(b)$, some corner cases are handled by allowing $i=-1$ or $j=-1$ and letting the corresponding cells in the table have infinite cost (a large enough number is used instead of infinity).

The formula used to compute $d[i,j]$ given earlier parts of the table is explicitly found in the code, so I'll let you figure it out on your own.