Skip to content

Commit

Permalink
Lookup table solution
Browse files Browse the repository at this point in the history
  • Loading branch information
romaf5 committed Oct 27, 2024
1 parent 066f13d commit bca7efc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion labs/bad_speculation/lookup_tables_1/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ static std::size_t mapToBucket(std::size_t v) {

std::array<std::size_t, NUM_BUCKETS> histogram(const std::vector<int> &values) {
std::array<std::size_t, NUM_BUCKETS> retBuckets{0};
std::array<std::size_t, 151> bucket_map;
for (int i = 0; i < 151; ++i) {
bucket_map[i] = mapToBucket(i);
}
for (auto v : values) {
retBuckets[mapToBucket(v)]++;
retBuckets[bucket_map[v]]++;
}
return retBuckets;
}

0 comments on commit bca7efc

Please sign in to comment.