From d67d54ddd018f53c3f164943896b0a9a74e3e76c Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Mon, 13 Feb 2017 13:27:43 -0800 Subject: [PATCH] Change how 32bit hashes are calculated to prevent collisions --- hecl/blender/hecl_blendershell.py | 3 ++- hecl/include/hecl/hecl.hpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hecl/blender/hecl_blendershell.py b/hecl/blender/hecl_blendershell.py index 5d2397883..9cfd115e9 100644 --- a/hecl/blender/hecl_blendershell.py +++ b/hecl/blender/hecl_blendershell.py @@ -51,7 +51,8 @@ class PathHasher: writepipestr(path.encode()) read_str = readpipestr() 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 def hashpath64(self, path): diff --git a/hecl/include/hecl/hecl.hpp b/hecl/include/hecl/hecl.hpp index be599cd57..56b80fd9f 100644 --- a/hecl/include/hecl/hecl.hpp +++ b/hecl/include/hecl/hecl.hpp @@ -536,7 +536,7 @@ public: Hash(uint64_t hashin) : hash(hashin) {} 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);} size_t valSizeT() const {return size_t(hash);} Hash& operator=(const Hash& other) {hash = other.hash; return *this;}