treelite
categorical_bitmap.h
Go to the documentation of this file.
1 
7 #ifndef TREELITE_COMPILER_COMMON_CATEGORICAL_BITMAP_H_
8 #define TREELITE_COMPILER_COMMON_CATEGORICAL_BITMAP_H_
9 
10 #include <vector>
11 
12 namespace treelite {
13 namespace compiler {
14 namespace common_util {
15 
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};
21  }
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 (size_t i = 0; i < left_categories.size(); ++i) {
25  const uint32_t cat = left_categories[i];
26  const size_t idx = cat / 64;
27  const uint32_t offset = cat % 64;
28  bitmap[idx] |= (static_cast<uint64_t>(1) << offset);
29  }
30  return bitmap;
31 }
32 
33 } // namespace common_util
34 } // namespace compiler
35 } // namespace treelite
36 
37 #endif // TREELITE_COMPILER_COMMON_CATEGORICAL_BITMAP_H_