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>& left_categories) {
18 const size_t num_left_categories = left_categories.size();
19 if (num_left_categories == 0) {
20 return std::vector<uint64_t>{0};
22 const uint32_t max_left_category = left_categories[num_left_categories - 1];
23 std::vector<uint64_t> bitmap((max_left_category + 1 + 63) / 64, 0);
24 for (uint32_t cat : left_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_