From 2d30772c90f54d7f2ae16fee4d16276718157129 Mon Sep 17 00:00:00 2001 From: Vladyslav Usenko Date: Tue, 28 Apr 2020 11:45:54 +0200 Subject: [PATCH] small change hash_bow --- include/basalt/hash_bow/hash_bow.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/basalt/hash_bow/hash_bow.h b/include/basalt/hash_bow/hash_bow.h index 5bf7a87..f2faab3 100644 --- a/include/basalt/hash_bow/hash_bow.h +++ b/include/basalt/hash_bow/hash_bow.h @@ -92,10 +92,13 @@ class HashBow { for (const auto& kv : scores) results.emplace_back(kv.first, -kv.second / 2.0); - std::sort(results.begin(), results.end(), - [](const auto& a, const auto& b) { return a.second > b.second; }); + 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; }); - if (results.size() > num_results) results.resize(num_results); + results.resize(num_results); + } } protected: