Change how 32bit hashes are calculated to prevent collisions

This commit is contained in:
Phillip Stephens 2017-02-13 13:27:43 -08:00
parent 86f9f62ef6
commit d67d54ddd0
2 changed files with 3 additions and 2 deletions

View File

@ -51,7 +51,8 @@ class PathHasher:
writepipestr(path.encode()) writepipestr(path.encode())
read_str = readpipestr() read_str = readpipestr()
if len(read_str) >= 16: if len(read_str) >= 16:
return int(read_str[0:16], 16) & 0xffffffff hash = int(read_str[0:16], 16)
return (hash & 0xffffffff) ^ ((hash >> 32) & 0xffffffff)
return 0 return 0
def hashpath64(self, path): def hashpath64(self, path):

View File

@ -536,7 +536,7 @@ public:
Hash(uint64_t hashin) Hash(uint64_t hashin)
: hash(hashin) {} : hash(hashin) {}
Hash(const Hash& other) {hash = other.hash;} Hash(const Hash& other) {hash = other.hash;}
uint32_t val32() const {return uint32_t(hash);} uint32_t val32() const {return uint32_t(hash) ^ uint32_t(hash >> 32);}
uint64_t val64() const {return uint64_t(hash);} uint64_t val64() const {return uint64_t(hash);}
size_t valSizeT() const {return size_t(hash);} size_t valSizeT() const {return size_t(hash);}
Hash& operator=(const Hash& other) {hash = other.hash; return *this;} Hash& operator=(const Hash& other) {hash = other.hash; return *this;}