|
Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
Returns the Hamming distance between two integers. More...
#include <cassert>#include <iostream>Namespaces | |
| namespace | bit_manipulation |
| for std::vector | |
| namespace | hamming_distance |
| Functions for Hamming distance implementation. | |
Functions | |
| uint64_t | bit_manipulation::hamming_distance::bitCount (uint64_t value) |
| uint64_t | bit_manipulation::hamming_distance::hamming_distance (uint64_t a, uint64_t b) |
| uint64_t | bit_manipulation::hamming_distance::hamming_distance (const std::string &a, const std::string &b) |
| static void | test () |
| Function to the test hamming distance. More... | |
| int | main () |
| Main function. More... | |
Returns the Hamming distance between two integers.
To find hamming distance between two integers, we take their xor, which will have a set bit iff those bits differ in the two numbers. Hence, we return the number of such set bits.
| uint64_t bit_manipulation::hamming_distance::bitCount | ( | uint64_t | value | ) |
This function returns the number of set bits in the given number.
| value | the number of which we want to count the number of set bits. |
| uint64_t bit_manipulation::hamming_distance::hamming_distance | ( | const std::string & | a, |
| const std::string & | b | ||
| ) |
This function returns the hamming distance between two strings.
| a | the first string |
| b | the second string |
| uint64_t bit_manipulation::hamming_distance::hamming_distance | ( | uint64_t | a, |
| uint64_t | b | ||
| ) |
This function returns the hamming distance between two integers.
| a | the first number |
| b | the second number |
| int main | ( | void | ) |
Main function.
|
static |
Function to the test hamming distance.