small change hash_bow

This commit is contained in:
Vladyslav Usenko 2020-04-28 11:45:54 +02:00
parent eb5752770e
commit 2d30772c90
1 changed files with 6 additions and 3 deletions

View File

@ -92,10 +92,13 @@ class HashBow {
for (const auto& kv : scores) for (const auto& kv : scores)
results.emplace_back(kv.first, -kv.second / 2.0); results.emplace_back(kv.first, -kv.second / 2.0);
std::sort(results.begin(), results.end(), if (results.size() > num_results) {
std::partial_sort(
results.begin(), results.begin() + num_results, results.end(),
[](const auto& a, const auto& b) { return a.second > b.second; }); [](const auto& a, const auto& b) { return a.second > b.second; });
if (results.size() > num_results) results.resize(num_results); results.resize(num_results);
}
} }
protected: protected: