diff --git a/labs/bad_speculation/lookup_tables_1/solution.cpp b/labs/bad_speculation/lookup_tables_1/solution.cpp index 4c3786de..db23f1fd 100644 --- a/labs/bad_speculation/lookup_tables_1/solution.cpp +++ b/labs/bad_speculation/lookup_tables_1/solution.cpp @@ -1,48 +1,29 @@ #include "solution.hpp" +int bucket_map[151] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0-12 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 13-28 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 29-40 + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,// 41-52 + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // 53-70 + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, // 71-82 + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, // 83-99 + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // 100-109 + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7 +}; + static std::size_t mapToBucket(std::size_t v) { - // size of a bucket - if (v < 13) return 0; // 13 - else if (v < 29) return 1; // 16 - else if (v < 41) return 2; // 12 - else if (v < 53) return 3; // 12 - else if (v < 71) return 4; // 18 - else if (v < 83) return 5; // 12 - else if (v < 100) return 6; // 17 - return DEFAULT_BUCKET; + return bucket_map[v]; } std::array histogram(const std::vector &values) { std::array retBuckets{0}; - std::array bucket_map; - - 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; - } for (auto v : values) { - retBuckets[bucket_map[v]]++; + retBuckets[mapToBucket(v)]++; } return retBuckets; }