hash_combine moved to headers and tbb_hash left-overs

This commit is contained in:
Nikolaus Demmel 2020-06-23 16:59:15 +02:00
parent cfb6fc5b6d
commit 5de179de48
4 changed files with 14 additions and 28 deletions

View File

@ -72,7 +72,7 @@ class HashBow {
const int64_t* max_t_ns = nullptr) const { const int64_t* max_t_ns = nullptr) const {
results.clear(); results.clear();
std::unordered_map<TimeCamId, double, tbb::tbb_hash<TimeCamId>> scores; std::unordered_map<TimeCamId, double> scores;
for (const auto& kv : bow_vector) { for (const auto& kv : bow_vector) {
const auto range_it = inverted_index.find(kv.first); const auto range_it = inverted_index.find(kv.first);

View File

@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <unordered_map> #include <unordered_map>
#include <basalt/utils/assert.h> #include <basalt/utils/assert.h>
#include <basalt/utils/hash.h>
#if defined(BASALT_USE_CHOLMOD) #if defined(BASALT_USE_CHOLMOD)
@ -256,14 +257,10 @@ class SparseHashAccumulator {
inline size_t operator()(const KeyT& c) const { inline size_t operator()(const KeyT& c) const {
size_t seed = 0; size_t seed = 0;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
hash_combine(seed, std::hash<int>()(c[i])); hash_combine(seed, c[i]);
} }
return seed; return seed;
} }
inline void hash_combine(std::size_t& seed, std::size_t value) const {
seed ^= value + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
}; };
std::unordered_map<KeyT, MatrixX, KeyHash> hash_map; std::unordered_map<KeyT, MatrixX, KeyHash> hash_map;

View File

@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <Eigen/StdVector> #include <Eigen/StdVector>
#include <sophus/se3.hpp> #include <sophus/se3.hpp>
#include <basalt/utils/hash.h>
#include <basalt/utils/sophus_utils.hpp> #include <basalt/utils/sophus_utils.hpp>
namespace basalt { namespace basalt {
@ -268,6 +269,7 @@ using ImageProjections = std::map<TimeCamId, ImageProjection>;
/// inlier projections indexed per track /// inlier projections indexed per track
using TrackProjections = using TrackProjections =
std::unordered_map<TrackId, std::map<TimeCamId, ProjectedLandmarkConstPtr>>; std::unordered_map<TrackId, std::map<TimeCamId, ProjectedLandmarkConstPtr>>;
} // namespace basalt } // namespace basalt
namespace cereal { namespace cereal {
@ -286,20 +288,17 @@ template <class Archive>
void serialize(Archive& ar, basalt::MatchData& c) { void serialize(Archive& ar, basalt::MatchData& c) {
ar(c.T_i_j, c.matches, c.inliers); ar(c.T_i_j, c.matches, c.inliers);
} }
} // namespace cereal } // namespace cereal
namespace std { namespace std {
inline void hash_combine(std::size_t& seed, std::size_t value) {
seed ^= value + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
template <> template <>
struct hash<basalt::TimeCamId> { struct hash<basalt::TimeCamId> {
size_t operator()(const basalt::TimeCamId& x) const { size_t operator()(const basalt::TimeCamId& x) const {
size_t seed = 0; size_t seed = 0;
hash_combine(seed, std::hash<int>()(x.frame_id)); basalt::hash_combine(seed, x.frame_id);
hash_combine(seed, std::hash<int>()(x.cam_id)); basalt::hash_combine(seed, x.cam_id);
return seed; return seed;
} }
}; };
@ -309,22 +308,12 @@ struct hash<std::pair<basalt::TimeCamId, basalt::TimeCamId>> {
size_t operator()( size_t operator()(
const std::pair<basalt::TimeCamId, basalt::TimeCamId>& x) const { const std::pair<basalt::TimeCamId, basalt::TimeCamId>& x) const {
size_t seed = 0; size_t seed = 0;
hash_combine(seed, std::hash<int>()(x.first.frame_id)); basalt::hash_combine(seed, x.first.frame_id);
hash_combine(seed, std::hash<int>()(x.first.cam_id)); basalt::hash_combine(seed, x.first.cam_id);
hash_combine(seed, std::hash<int>()(x.second.frame_id)); basalt::hash_combine(seed, x.second.frame_id);
hash_combine(seed, std::hash<int>()(x.second.cam_id)); basalt::hash_combine(seed, x.second.cam_id);
return seed; return seed;
} }
}; };
} // namespace std } // namespace std
namespace tbb {
template <>
struct tbb_hash<basalt::TimeCamId> : public std::hash<basalt::TimeCamId> {};
template <>
struct tbb_hash<std::pair<basalt::TimeCamId, basalt::TimeCamId>>
: public std::hash<std::pair<basalt::TimeCamId, basalt::TimeCamId>> {};
} // namespace tbb

@ -1 +1 @@
Subproject commit b068d7a967af52fb3c8e261829b16a2403845ef8 Subproject commit d6a1bc24376a67b11bd13e44cf75c1e4351f359a