2^53 : 9007199254740992 : 0x20000000000000
Max value of unsigned long long :
2^64 : 18446744073709551615 : 0xFFFFFFFFFFFFFFFF
There are two solutions:
- Using Big integer library like http://silentmatt.com/biginteger/
- Using Hexadecimal String for output
We decided to use solution 2, because
- hash value is used only to be sent to php API page
- do not need calculation
- later, when another hash algorithm is used, it can be much longer
After adopting this solution, following modules are affected.
phash : hash generator from image
I changed the code from generating integer string to generating hexadecimal string.
//printf("%llun", tmphash); printf("%016llXn", tmphash);
- hamming : hamming distance calculator from two hash values
I changed it to get hexadecimal string :
// ulong64 hash1 = strtoull(argv, NULL, 10); // ulong64 hash2 = strtoull(argv, NULL, 10); ulong64 hash1 = strtoull(argv, NULL, 16); ulong64 hash2 = strtoull(argv, NULL, 16);
- regdaemon : C++ daemon
I changed add/match command so it gets hexadecimal string.
//uint64_t uiHash = std::stoull(strHash); uint64_t uiHash = std::stoull(strHash, 0, 16);
php API doesn’t have to changed because it bypasses by base64 encoding.
For MySQL database field, we decided to keep 64bit unsigned integer type for DCT hash value. That is because this way doesn’t need to be changed from string type to number type to load on the memory for indexing.