31 const size_t* begin{
nullptr};
32 const size_t* end{
nullptr};
37 Elem(
const size_t* begin,
40 : begin(begin), end(end), node_id(node_id) {}
42 inline size_t Size()
const {
47 std::vector<Elem>::const_iterator begin()
const {
48 return elem_of_each_node_.begin();
51 std::vector<Elem>::const_iterator end()
const {
52 return elem_of_each_node_.end();
55 size_t Size()
const {
return std::distance(begin(), end()); }
59 const Elem& e = elem_of_each_node_[node_id];
65 Elem& e = elem_of_each_node_[node_id];
71 elem_of_each_node_.clear();
75 CHECK_EQ(elem_of_each_node_.size(), 0U);
77 if (row_indices_.empty()) {
78 constexpr size_t* kBegin =
nullptr;
79 constexpr size_t* kEnd =
nullptr;
80 static_assert(kEnd - kBegin == 0);
81 elem_of_each_node_.emplace_back(kBegin, kEnd, 0);
86 const size_t* end =
dmlc::BeginPtr(row_indices_) + row_indices_.size();
87 elem_of_each_node_.emplace_back(begin, end, 0);
90 std::vector<size_t>* Data() {
return &row_indices_; }
91 std::vector<size_t>
const* Data()
const {
return &row_indices_; }
94 inline void AddSplit(
unsigned node_id,
unsigned left_node_id,
unsigned right_node_id,
95 size_t n_left,
size_t n_right) {
96 const Elem e = elem_of_each_node_[node_id];
98 size_t* all_begin{
nullptr};
99 size_t* begin{
nullptr};
100 if (e.begin ==
nullptr) {
102 CHECK_EQ(n_right, 0);
105 begin = all_begin + (e.begin - all_begin);
108 CHECK_EQ(n_left + n_right, e.Size());
109 CHECK_LE(begin + n_left, e.end);
110 CHECK_EQ(begin + n_left + n_right, e.end);
112 if (left_node_id >= elem_of_each_node_.size()) {
113 elem_of_each_node_.resize(left_node_id + 1, Elem(
nullptr,
nullptr, -1));
115 if (right_node_id >= elem_of_each_node_.size()) {
116 elem_of_each_node_.resize(right_node_id + 1, Elem(
nullptr,
nullptr, -1));
119 elem_of_each_node_[left_node_id] = Elem(begin, begin + n_left, left_node_id);
120 elem_of_each_node_[right_node_id] = Elem(begin + n_left, e.end, right_node_id);
121 elem_of_each_node_[node_id] = Elem(
nullptr,
nullptr, -1);
126 std::vector<size_t> row_indices_;
128 std::vector<Elem> elem_of_each_node_;