From 5905c085c6e92670686bb830c318938af86ec7c1 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 27 Jan 2020 04:04:02 +0800 Subject: [PATCH] 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. --- src/base/bittorrent/trackerentry.cpp | 2 +- src/base/net/downloadmanager.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/trackerentry.cpp b/src/base/bittorrent/trackerentry.cpp index ca13b059a..34ad1bfb0 100644 --- a/src/base/bittorrent/trackerentry.cpp +++ b/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) { - return (::qHash(key.url(), seed) ^ key.tier()); + return (::qHash(key.url(), seed) ^ ::qHash(key.tier())); } diff --git a/src/base/net/downloadmanager.cpp b/src/base/net/downloadmanager.cpp index ad6725a94..ffa3c28a7 100644 --- a/src/base/net/downloadmanager.cpp +++ b/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) { - return ::qHash(serviceID.hostName, seed) ^ serviceID.port; + return ::qHash(serviceID.hostName, seed) ^ ::qHash(serviceID.port); } bool Net::operator==(const ServiceID &lhs, const ServiceID &rhs)