Browse Source

Use systematic approach to generate hash

The basic idea is to hash each class member and then mix them with xor
operation.
However the `seed` must be handled with care, it should only be
introduced once when mixing the hashes of each class member, otherwise
under some circumstances the `seed` might xor with itself and thus break
the intended effect.
adaptive-webui-19844
Chocobo1 5 years ago
parent
commit
5905c085c6
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 2
      src/base/bittorrent/trackerentry.cpp
  2. 2
      src/base/net/downloadmanager.cpp

2
src/base/bittorrent/trackerentry.cpp

@ -162,5 +162,5 @@ bool BitTorrent::operator==(const TrackerEntry &left, const TrackerEntry &right)
uint BitTorrent::qHash(const TrackerEntry &key, const uint seed) uint BitTorrent::qHash(const TrackerEntry &key, const uint seed)
{ {
return (::qHash(key.url(), seed) ^ key.tier()); return (::qHash(key.url(), seed) ^ ::qHash(key.tier()));
} }

2
src/base/net/downloadmanager.cpp

@ -348,7 +348,7 @@ Net::ServiceID Net::ServiceID::fromURL(const QUrl &url)
uint Net::qHash(const ServiceID &serviceID, const uint seed) uint Net::qHash(const ServiceID &serviceID, const uint seed)
{ {
return ::qHash(serviceID.hostName, seed) ^ serviceID.port; return ::qHash(serviceID.hostName, seed) ^ ::qHash(serviceID.port);
} }
bool Net::operator==(const ServiceID &lhs, const ServiceID &rhs) bool Net::operator==(const ServiceID &lhs, const ServiceID &rhs)

Loading…
Cancel
Save