Basic group by code
Implement split_indices in C++