From 94fb407b0a3450a91decfff14d4a71fdcdf59bd8 Mon Sep 17 00:00:00 2001 From: Ravishankar Joshi <21024229+ravibitsgoa@users.noreply.github.com> Date: Mon, 26 Oct 2020 08:18:17 +0530 Subject: [PATCH] Apply suggestions from code review Co-authored-by: David Leal --- bit_manipulation/hamming_distance.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/bit_manipulation/hamming_distance.cpp b/bit_manipulation/hamming_distance.cpp index 1429068db..c7e62528f 100644 --- a/bit_manipulation/hamming_distance.cpp +++ b/bit_manipulation/hamming_distance.cpp @@ -12,9 +12,14 @@ * @author [Ravishankar Joshi](https://github.com/ravibitsgoa) */ -#include +#include /// for assert #include /// for io operations +/** + * @namespace bit_manipulation + * @brief Bit Manipulation algorithms + */ +namespace bit_manipulation { /** * This function returns the number of set bits in the given number. * @param value the number of which we want to count the number of set bits. @@ -38,15 +43,16 @@ uint64_t bitCount(uint64_t value) { * @returns the number of bits differing between the two integers. */ uint64_t hamming_distance(uint64_t a, uint64_t b) { return bitCount(a ^ b); } +} // namespace bit_manipulation /** * @brief Function to the test hamming distance. * @returns void */ static void test() { - assert(hamming_distance(11, 2) == 2); - assert(hamming_distance(2, 0) == 1); - assert(hamming_distance(11, 0) == 3); + assert(bit_manipulation::hamming_distance(11, 2) == 2); + assert(bit_manipulation::hamming_distance(2, 0) == 1); + assert(bit_manipulation::hamming_distance(11, 0) == 3); } /** @@ -54,10 +60,10 @@ static void test() { * @returns 0 on exit */ int main() { - test(); + test(); // execute the tests uint64_t a = 11; // 1011 in binary uint64_t b = 2; // 0010 in binary std::cout << "Hamming distance between " << a << " and " << b << " is " - << hamming_distance(a, b) << std::endl; + << bit_manipulation::hamming_distance(a, b) << std::endl; }