Update inverted index for HashBow

This commit is contained in:
Vladyslav Usenko 2019-08-12 12:48:37 +02:00
parent 4099457045
commit de3e23ce2a
1 changed files with 14 additions and 11 deletions

View File

@ -9,6 +9,7 @@
#include <basalt/utils/common_types.h> #include <basalt/utils/common_types.h>
#include <tbb/concurrent_unordered_map.h> #include <tbb/concurrent_unordered_map.h>
#include <tbb/concurrent_vector.h>
namespace basalt { namespace basalt {
@ -61,8 +62,8 @@ class HashBow {
inline void add_to_database(const TimeCamId& tcid, inline void add_to_database(const TimeCamId& tcid,
const HashBowVector& bow_vector) { const HashBowVector& bow_vector) {
for (const auto& kv : bow_vector) { for (const auto& kv : bow_vector) {
std::pair<TimeCamId, double> p = std::make_pair(tcid, kv.second); // std::pair<TimeCamId, double> p = std::make_pair(tcid, kv.second);
inverted_index.emplace(kv.first, p); inverted_index[kv.first].emplace_back(tcid, kv.second);
} }
} }
@ -75,14 +76,15 @@ class HashBow {
std::unordered_map<TimeCamId, double, tbb::tbb_hash<TimeCamId>> scores; std::unordered_map<TimeCamId, double, tbb::tbb_hash<TimeCamId>> scores;
for (const auto& kv : bow_vector) { for (const auto& kv : bow_vector) {
const auto range_it = inverted_index.equal_range(kv.first); const auto range_it = inverted_index.find(kv.first);
for (auto it = range_it.first; it != range_it.second; ++it) { if (range_it != inverted_index.end())
// if there is a maximum query time select only the frames that have for (const auto& v : range_it->second) {
// timestamp below max_t_ns // if there is a maximum query time select only the frames that have
if (!max_t_ns || it->second.first.frame_id < (*max_t_ns)) // timestamp below max_t_ns
scores[it->second.first] += kv.second * it->second.second; if (!max_t_ns || v.first.frame_id < (*max_t_ns))
} scores[v.first] += kv.second * v.second;
}
} }
results.reserve(scores.size()); results.reserve(scores.size());
@ -152,8 +154,9 @@ class HashBow {
size_t num_bits; size_t num_bits;
tbb::concurrent_unordered_multimap<FeatureHash, std::pair<TimeCamId, double>, tbb::concurrent_unordered_map<
std::hash<FeatureHash>> FeatureHash, tbb::concurrent_vector<std::pair<TimeCamId, double>>,
std::hash<FeatureHash>>
inverted_index; inverted_index;
}; };