7 #ifndef TREELITE_COMPILER_COMMON_CATEGORICAL_BITMAP_H_ 8 #define TREELITE_COMPILER_COMMON_CATEGORICAL_BITMAP_H_ 14 namespace common_util {
16 inline std::vector<uint64_t>
17 GetCategoricalBitmap(
const std::vector<uint32_t>& matching_categories) {
18 const size_t num_matching_categories = matching_categories.size();
19 if (num_matching_categories == 0) {
20 return std::vector<uint64_t>{0};
22 const uint32_t max_matching_category = matching_categories[num_matching_categories - 1];
23 std::vector<uint64_t> bitmap((max_matching_category + 1 + 63) / 64, 0);
24 for (uint32_t cat : matching_categories) {
25 const size_t idx = cat / 64;
26 const uint32_t offset = cat % 64;
27 bitmap[idx] |= (
static_cast<uint64_t
>(1) << offset);
36 #endif // TREELITE_COMPILER_COMMON_CATEGORICAL_BITMAP_H_