Skip to content

Commit

Permalink
Increase performance of AccumulateClues by preallocating and utilizin…
Browse files Browse the repository at this point in the history
…g try_emplace
  • Loading branch information
ol-imorozko committed Oct 5, 2024
1 parent fccf6ae commit 3b2b34f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/core/algorithms/dc/FastADC/util/clue_set_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ inline ClueSet BuildClueSet(std::vector<PliShard> const& pliShards, PredicatePac
}

for (auto const& [clue, count] : partial_clue_set) {
clue_set[clue] += count;
auto [it, inserted] = clue_set.try_emplace(clue, count);
if (!inserted) {
it->second += count;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ ClueSet AccumulateClues(Vectors const&... vectors) {
ClueSet clue_set;
int64_t clue_zero_count = 0;

clue_set.reserve((vectors.size() + ...));

auto insert_clues = [&](std::vector<Clue> const& clues) {
for (auto const& clue : clues) {
if (clue.none()) {
++clue_zero_count;
} else {
clue_set[clue]++;
auto [it, inserted] = clue_set.try_emplace(clue, 1);
if (!inserted) it->second++;
}
}
};
Expand Down

0 comments on commit 3b2b34f

Please sign in to comment.