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>& 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};
21  }
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);
28  }
29  return bitmap;
30 }
31 
32 } // namespace common_util
33 } // namespace compiler
34 } // namespace treelite
35 
36 #endif // TREELITE_COMPILER_COMMON_CATEGORICAL_BITMAP_H_