restore hamming distance calc