开发者

generate unique hash keys of url

开发者 https://www.devze.com 2023-03-06 16:04 出处:网络
i want to ge开发者_JAVA技巧nerate unique hash keys of an url. atm im using boost hash std::size_t seed = 0;

i want to ge开发者_JAVA技巧nerate unique hash keys of an url. 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 the hash keys are very often duplicate... :(

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

does someone have a SIMPLE alternative?


I don't think there's an error in that code. The hash values are different with 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 your host, path, etc... are char*s, and you're reusing those pointers, then the result you're getting makes sens. There is no overload of hash_value for char*. So the only thing that will go into the computation is the pointer value itself (exactly how is not defined). (See the very bottom of the hash reference.)

Other point: this 9223372036854775807 value is quite special. Its hex representation is:

0x7fffffffffffffff

So you probably have a conversion/overflow problem somewhere that is not visible in what you posted.


Try with some md5 functions implemented for C

0

精彩评论

暂无评论...
验证码 换一张
取 消