Skip to content

Commit

Permalink
Lookup tables v3
Browse files Browse the repository at this point in the history
  • Loading branch information
romaf5 committed Oct 27, 2024
1 parent 149709c commit bc4d40e
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions labs/bad_speculation/lookup_tables_1/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,29 @@ 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 < 100; ++i) {
bucket_map[i] = mapToBucket(i);

for (int i = 0; i < 13; ++i) {
bucket_map[i] = 0;
}
for (int i = 13; i < 29; ++i) {
bucket_map[i] = 1;
}
for (int i = 29; i < 41; ++i) {
bucket_map[i] = 2;
}
for (int i = 41; i < 53; ++i) {
bucket_map[i] = 3;
}
for (int i = 53; i < 71; ++i) {
bucket_map[i] = 4;
}
for (int i = 71; i < 83; ++i) {
bucket_map[i] = 5;
}
for (int i = 83; i < 100; ++i) {
bucket_map[i] = 6;
}

for (int i = 100; i <= 150; ++i) {
bucket_map[i] = DEFAULT_BUCKET;
}
Expand Down

0 comments on commit bc4d40e

Please sign in to comment.