Go to the documentation of this file.00001 #ifndef Utils_h
00002 #define Utils_h
00003
00005 template<typename Reference, typename Association>
00006 std::pair<typename Association::data_type::first_type, double> match (Reference key, Association association, bool bestMatchByMaxValue)
00007 {
00008 typename Association::data_type::first_type value;
00009
00010 typename Association::const_iterator pos = association.find(key);
00011
00012 if (pos == association.end()) return std::pair<typename Association::data_type::first_type, double> (value, 0);
00013
00014 const std::vector<typename Association::data_type> & matches = pos->val;
00015
00016 double q = bestMatchByMaxValue ? -1e30 : 1e30;
00017
00018 for (std::size_t i = 0; i < matches.size(); ++i)
00019 if (bestMatchByMaxValue ? (matches[i].second > q) : (matches[i].second < q))
00020 {
00021 value = matches[i].first;
00022 q = matches[i].second;
00023 }
00024
00025 return std::pair<typename Association::data_type::first_type, double> (value, q);
00026 }
00027
00028 #endif