  In order to build a large scale quantum computer, one must be able to correct
errors extremely fast. We design a fast decoding algorithm for topological
codes to correct for Pauli errors and erasure and combination of both errors
and erasure. Our algorithm has a worst case complexity of $O(n \alpha(n))$,
where $n$ is the number of physical qubits and $\alpha$ is the inverse of
Ackermann's function, which is very slowly growing. For all practical purposes,
$\alpha(n) \leq 3$. We prove that our algorithm performs optimally for errors
of weight up to $(d-1)/2$ and for loss of up to $d-1$ qubits, where $d$ is the
minimum distance of the code. Numerically, we obtain a threshold of $9.9\%$ for
the 2d-toric code with perfect syndrome measurements and $2.6\%$ with faulty
measurements.
