Skip to content

Commit

Permalink
Add 1 to indices at collection time, so that the rest of the group_by…
Browse files Browse the repository at this point in the history
… algorithm can still use 0-based.
  • Loading branch information
romainfrancois committed May 28, 2018
1 parent 38be240 commit c5fc0d2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/group_indices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ class IntRange {
int size;
};

inline int plus_one(int i) { return i + 1; }

class ListCollecter {
public:
ListCollecter(List& data_): data(data_), index(0) {}

int collect(const std::vector<int>& indices) {
data[index] = indices;
data[index] = IntegerVector( indices.begin(), indices.end(), plus_one );
return index++;
}

Expand Down Expand Up @@ -455,6 +457,7 @@ SEXP build_index_cpp(const DataFrame& data, const SymbolVector& vars) {
vec_groups[i] = Rf_allocVector(TYPEOF(visited_data[i]), ncases);
copy_most_attributes(vec_groups[i], visited_data[i]);
}

vec_groups[nvars] = indices;
groups_names[nvars] = ".rows";
s->make(vec_groups, indices_collecter);
Expand Down

0 comments on commit c5fc0d2

Please sign in to comment.