#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <sstream>
#include <deque>
struct CSelection : public std::vector<std::deque<int> *>
{
size_t size()
{
size_t retval = 0;
for(auto &ptr : *this)
retval += ptr->size();
return retval;
}
};
struct C : public std::map< std::vector<std::string>, std::deque<int> >
{
// size_t size()
// {
// size_t retval=0;
// for(auto &[k,v]: *this)
// retval += v.size();
// return retval;
// }
CSelection findall(const std::vector<std::vector<std::string>> &keys)
{
CSelection retval;
for(auto &key:keys)
if(this->count(key))
retval.push_back(& (*this)[key]);
return retval;
}
void emplace_back(int i)
{
std::vector<std::string> key(i, std::to_string(i));
(*this)[key].emplace_back(i);
}
};
int main() {
C m;
//std::map< std::vector<std::string>, std::deque<int> > m;
m[{"hello","world"}]={1};
m[{"momma"}]={2};
m[{"a","b"}]={3};
m[{"momma","zz"}]={4};
m[{"zz","momma","b"}]={5};
m[{"zz","momma","a"}]={6,7};
m.emplace_back(4);
fprintf(stderr,"m.size %ld\n", m.size());
for(auto &[k,v]: m)
{
std::ostringstream strm;
for(auto &kv: k)
strm << ((&kv == &*k.begin())?"[":",") << kv;
strm << "]";
std::ostringstream strm2;
for(auto &vv: v)
strm2 << ((&vv == &*v.begin())?"[":",") << vv;
strm2 << "]";
fprintf(stderr,"k.size %ld, k %s, v.size %ld, v %s\n", k.size(), strm.str().c_str(), v.size(), strm2.str().c_str());
}
fprintf(stderr,"---\n");
auto selection = m.findall({{"momma"},{"a","b"},{"zz","momma","a"}});
for(auto &_v : selection)
{
auto &v = *_v;
std::ostringstream strm2;
for(auto &vv: v)
strm2 << ((&vv == &*v.begin())?"[":",") << vv;
strm2 << "]";
fprintf(stderr,"v.size %ld, v %s\n", v.size(), strm2.str().c_str());
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: