Add Grouper: Maps a key to a vectors

This commit is contained in:
Albert S. 2022-04-03 11:05:13 +02:00
förälder 82c081385b
incheckning e217218a3f
2 ändrade filer med 26 tillägg och 0 borttagningar

0
grouper.cpp Normal file
Visa fil

26
grouper.h Normal file
Visa fil

@ -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;
}
};