Skip to content

Commit e787624

Browse files
authored
Speed up PPFRegistration by using a hash function with fewer collisions (#6223)
* speed_up_ppf_hash_search * Update ppf_registration.h
1 parent 1590ba5 commit e787624

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

registration/include/pcl/registration/ppf_registration.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,18 @@ class PCL_EXPORTS PPFHashMapSearch {
6767
std::size_t
6868
operator()(const HashKeyStruct& s) const noexcept
6969
{
70-
const std::size_t h1 = std::hash<int>{}(s.first);
71-
const std::size_t h2 = std::hash<int>{}(s.second.first);
72-
const std::size_t h3 = std::hash<int>{}(s.second.second.first);
73-
const std::size_t h4 = std::hash<int>{}(s.second.second.second);
74-
return h1 ^ (h2 << 1) ^ (h3 << 2) ^ (h4 << 3);
70+
/// RS hash function https://www.partow.net/programming/hashfunctions/index.html
71+
std::size_t b_ = 378551;
72+
std::size_t a_ = 63689;
73+
std::size_t hash = 0;
74+
hash = hash * a_ + s.first;
75+
a_ = a_ * b_;
76+
hash = hash * a_ + s.second.first;
77+
a_ = a_ * b_;
78+
hash = hash * a_ + s.second.second.first;
79+
a_ = a_ * b_;
80+
hash = hash * a_ + s.second.second.second;
81+
return hash;
7582
}
7683
};
7784
using FeatureHashMapType =

0 commit comments

Comments
 (0)