Generate unique URL hash keys

I want to generate unique url hash keys. atm im using boost hash

  std::size_t seed = 0;
  boost::hash_combine(seed, host);
  boost::hash_combine(seed, path);
  boost::hash_combine(seed, query); 
  boost::hash_combine(seed, fragment);

but hash keys are very often repeated ... :(

http://www.finanzen.de/geldanlage-boerse.html  9223372036854775807                  
http://www.finanzen.de/geldanlage-china.html   9223372036854775807

Does anyone have a simple alternative?

+3
source share
2 answers

I do not think there is an error in this code. The hash values ​​are different from this dummy example:

#include <boost/functional/hash.hpp>
#include <cstdio>

int main()
{
    size_t seed = 0;
    std::string s1("www.finanzen.de");
    std::string s2("geldanlage-boerse.html");
    std::string s3("geldanlage-china.html");

    boost::hash_combine(seed, s1);
    boost::hash_combine(seed, s2);
    fprintf(stdout, "%016lx\n", seed);

    seed = 0;
    boost::hash_combine(seed, s1);
    boost::hash_combine(seed, s3);
    fprintf(stdout, "%016lx\n", seed);
    return 0;
}

Now, if yours host, pathetc. are char*s, and you reuse these pointers, then the result you get becomes sensitive. No overload hash_valuefor char*. Thus, the only thing that goes into the calculation is the value of the pointer itself (just like it is not defined). (See the bottom of the hash link .)

: 9223372036854775807 . :

0x7fffffffffffffff

, , / -, , .

+4

md5 C

0

All Articles