1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
template <class StreamClass> void readFile(map<int,set<string> >& map,StreamClass& stream)
{
foreach(line,stream)
{ //for each line, split it into parts delimited by ,
auto parts=explode(line,',');
map[StrToInt(explode(parts[0],':')[0])].insert(implode(parts,',',IDM_NOLASTDELIM,3)); //add "relevant" part
}
}
int main()
{
//open file1 and file2 here
map<int,set<string> > map1,map2;
readFile(map1,file1);
readFile(map2,file2);
bool map2ContainsAllEntries=true;
foreach(kv_pair,map1)
{ //for each set...
auto& aset=map2[kv_pair.first]; //cache the corresponding set in the second map
foreach(str,kv_pair.second)
{ //for each string in the set of the first map, check if it exists in the corresponding set in the second map
if (find(aset.begin(),aset.end(),str)==aset.end())
{ //if not, we can stop right away
map2ContainsAllEntries=false;
break;
}
}
if (!map2ContainsAllEntries)break;
}
}
|