I needed to sort vertices into buckets as an optimization for collision detection later. I came up with this:
Go over all the vertices and count the size that each bucket needs to be to contain them into an array.
Shift the size array index by -1 unit and use it as offset array instead.
Create a single array for all the indices, go over all the vertices again and place their indices according to the offsets while bumping the offset each time.
Use the index list to translate vertices to their new positions (or optionally move the vertices on step 3 if you don't need a map but I did for transforming other primitives).
Surprisingly enough, it's much faster than std::sort (by 10x) or a gpu bitonic sort (by 13x) that I implemented earlier. It can't be a new idea since it's so simplistic in its concept. So what is it called? I want to see what other people have done with it to perhaps make it even faster.