14 #ifndef XGBOOST_COMMON_GROUP_DATA_H_
15 #define XGBOOST_COMMON_GROUP_DATA_H_
31 template<
typename ValueType,
typename SizeType = bst_u
long>
45 std::vector<ValueType> *p_data,
46 size_t base_row_offset = 0)
49 base_row_offset_(base_row_offset) {}
58 thread_rptr_.resize(nthread);
59 for (std::size_t i = 0; i < thread_rptr_.size(); ++i) {
60 thread_rptr_[i].resize(max_key - std::min(base_row_offset_, max_key), 0);
70 void AddBudget(std::size_t key,
int threadid, SizeType nelem = 1) {
71 std::vector<SizeType> &trptr = thread_rptr_[threadid];
72 size_t offset_key = key - base_row_offset_;
73 if (trptr.size() < offset_key + 1) {
74 trptr.resize(offset_key + 1, 0);
76 trptr[offset_key] += nelem;
82 SizeType rptr_fill_value = rptr_.empty() ? 0 : rptr_.back();
83 for (std::size_t tid = 0; tid < thread_rptr_.size(); ++tid) {
84 if (rptr_.size() <= thread_rptr_[tid].size() + base_row_offset_) {
85 rptr_.resize(thread_rptr_[tid].size() + base_row_offset_ + 1,
90 std::size_t count = 0;
91 for (std::size_t i = base_row_offset_; i + 1 < rptr_.size(); ++i) {
92 for (std::size_t tid = 0; tid < thread_rptr_.size(); ++tid) {
93 std::vector<SizeType> &trptr = thread_rptr_[tid];
94 if (i < trptr.size() +
96 std::size_t thread_count =
97 trptr[i - base_row_offset_];
98 trptr[i - base_row_offset_] = count + rptr_.back();
99 count += thread_count;
102 rptr_[i + 1] += count;
104 data_.resize(rptr_.back());
115 void Push(std::size_t key, ValueType&& value,
int threadid) {
116 size_t offset_key = key - base_row_offset_;
117 SizeType &rp = thread_rptr_[threadid][offset_key];
118 data_[rp++] = std::move(value);
123 std::vector<SizeType> &rptr_;
125 std::vector<ValueType> &data_;
127 std::vector<std::vector<SizeType> > thread_rptr_;
129 size_t base_row_offset_;
133 #endif // XGBOOST_COMMON_GROUP_DATA_H_