Add Grouper: Maps a key to a vectors

Tá an tiomantas seo le fáil i:
Albert S. 2022-04-03 11:05:13 +02:00
tuismitheoir 82c081385b
tiomantas e217218a3f
D'athraigh 2 comhad le 26 breiseanna agus 0 scriosta

0
grouper.cpp Comhad gnáth
Féach ar an gComhad

26
grouper.h Comhad gnáth
Féach ar an gComhad

@ -0,0 +1,26 @@
#include "utils.h"
template<class G, class V, class C>
class Grouper
{
std::map<G, std::vector<const V*>, C> results;
public:
Grouper(C c)
{
results = std::map<G, std::vector<const V*>, C>(c);
}
void group(const std::function<G(const V&)> &map, const std::vector<V> &values)
{
for(const V &v : values)
{
results[map(v)].push_back(&v);
}
}
std::map<G, std::vector<const V*>, C> &getResults()
{
return this->results;
}
};