mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-07 20:20:17 +00:00
Pre-size scores in find_perfect_hash_seed
This improves startup of a small Python file by 1.35% (instruction count from Callgrind) for me.
This commit is contained in:
parent
1ea7c151a3
commit
15758d448d
@ -52,7 +52,7 @@ namespace pkpy{
|
||||
uint32_t find_perfect_hash_seed(uint32_t capacity, const std::vector<StrName>& keys){
|
||||
if(keys.empty()) return kHashSeeds[0];
|
||||
std::set<uint32_t> indices;
|
||||
std::vector<std::pair<uint32_t, float>> scores;
|
||||
std::vector<std::pair<uint32_t, float>> scores(kHashSeeds.size());
|
||||
for(int i=0; i<kHashSeeds.size(); i++){
|
||||
indices.clear();
|
||||
for(auto key: keys){
|
||||
@ -60,7 +60,7 @@ namespace pkpy{
|
||||
indices.insert(index);
|
||||
}
|
||||
float score = indices.size() / (float)keys.size();
|
||||
scores.push_back({kHashSeeds[i], score});
|
||||
scores[i] = {kHashSeeds[i], score};
|
||||
}
|
||||
std::sort(scores.begin(), scores.end(), [](auto a, auto b){ return a.second > b.second; });
|
||||
return scores[0].first;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user