Retrieving the most commonly occurring tuples?


I have a vector of tuples of the format:
thrust::device_vector<thrust::tuple<int, int, int> > data;

Ignore the last element in the tuple i.e. thrust::get<2>, as this just contains an index to another data structure. How do I return the vector of tuples that have the pair thrust::get<0> and thrust::get<1> occurring the most often?

E.g. if data contained

(1, 3, 0)
(4, 2, 1)
(5, 4, 5)
(4, 2, 3)
(2, 7, 7)

Would return (4, 2, 1) and (4, 2, 3) as the pair 4, 2 here appear most often (twice in this case). I was thinking of sorting first by thrust::get<0> and thrust::get<1> and then using unique_by_key_copy but couldn’t figure out a way to get thrust::sort working on tuples with a custom compare functor. Maybe there is a more efficient way anyway?

Thanks for any help,

Solved this. Got confused due to lack of sleep.