From c0661676529526c2de8d51b131c127df2454b31f Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Fri, 24 Feb 2023 11:17:01 -0500 Subject: [PATCH] Don't sort; just pick best score --- src/namedict.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/namedict.h b/src/namedict.h index 511dd042..193a064b 100644 --- a/src/namedict.h +++ b/src/namedict.h @@ -52,7 +52,8 @@ namespace pkpy{ uint32_t find_perfect_hash_seed(uint32_t capacity, const std::vector& keys){ if(keys.empty()) return kHashSeeds[0]; std::set indices; - std::vector> scores(kHashSeeds.size()); + uint32_t best_seed = 0; + float best_score = std::numeric_limits::max(); for(int i=0; i best_score) { + best_score = score; + best_seed = kHashSeeds[i]; + } } - std::sort(scores.begin(), scores.end(), [](auto a, auto b){ return a.second > b.second; }); - return scores[0].first; + return best_seed; } struct NameDict {