Skip to content

Commit 7a8ec2a

Browse files
committed
Fixing #90: Avoid overflow in OcTreeKey hashing function, also changed 1337 to prime number
1 parent b5a35ed commit 7a8ec2a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

octomap/include/octomap/OcTreeKey.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ namespace octomap {
9696
/// Provides a hash function on Keys
9797
struct KeyHash{
9898
size_t operator()(const OcTreeKey& key) const{
99-
// a hashing function
100-
return key.k[0] + 1337*key.k[1] + 345637*key.k[2];
99+
// a simple hashing function
100+
// explicit casts to size_t to operate on the complete range
101+
// constanst will be promoted according to C++ standard
102+
return size_t(key.k[0]) + 1447*size_t(key.k[1]) + 345637*size_t(key.k[2]);
101103
}
102104
};
103105

0 commit comments

Comments
 (0)