Add Grouper: Maps a key to a vectors
This commit is contained in:
szülő
82c081385b
commit
e217218a3f
0
grouper.cpp
Normal file
0
grouper.cpp
Normal file
26
grouper.h
Normal file
26
grouper.h
Normal file
@ -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;
|
||||
}
|
||||
};
|
Betöltés…
Reference in New Issue
Block a user