diff --git a/dlib/general_hash/count_bits.h b/dlib/general_hash/count_bits.h index 9b0529502..01acad2ab 100644 --- a/dlib/general_hash/count_bits.h +++ b/dlib/general_hash/count_bits.h @@ -54,6 +54,26 @@ namespace dlib return count_bits(a^b); } +// ---------------------------------------------------------------------------------------- + + template < + typename T + > + T hamming_distance ( + const std::pair& a, + const std::pair& b + ) + /*! + requires + - T is an unsigned integral type or a std::pair that, recursively, eventually + contains unsigned integral types. + ensures + - returns the number of bits which differ between a and b. + !*/ + { + return hamming_distance(a.first,b.first) + hamming_distance(a.second, b.second); + } + // ---------------------------------------------------------------------------------------- }