Archive for c++

Mapreduce simplified

Mapreduce is a process to find out number of similar banana in Iraq and Afganistan.

For example, you want to know how many green and white banana in Iraq and Afganistan. So, you hire a terrorist in these two countries to count green and white banana and ask them to sent back the result to you.
Counting algorithm is secret as it may disclose the location of terrorist. The result:

std::map<string, int> afganbanana;

afganbanana['white'] =100;

afganbanana['green'] =700;

std::map<string,int> iraqbanana;

iraqbanana['white'] =-900;

iraqbanana['green'] =-700;

You recieved the data and merge this two map by a really complicated reduce function:

map<string,int> reduce(map<string,int> banana1, map<string, int> banana2){

return merge(banana1, banana2);

}

reduce(iraqbanana, afganbanana)

cout<<banana['white']<<”:”<<banana['green]<<endl;

output:

-800 : 0
I think very few people are concern about mapreduce except FBI. FBI is investing huge in google to research about the

correlation between white banana and Osama bin laden.

Leave a Comment

Structure your data in c++ using stl container map, set

how to orgnanize structure in a c++ program.

map of a {string–> pointing to a set of integer } and traverse all the string and element of set

A dumb and obvious solution:

// be careful about > > , single space between this two bracket

std::map<string, std::set<int> > strToIntSet;

// declare an iterator

std::map<string, std::set<int> >::iterator it;

for (it=strToIntSet.begin(); it!=strToIntSet().end(); it++){

std::cout<<it->first<<” : “;

std::set<int>::iteator it1;

// Now print out each element of set

for (it1=it->second.begin(); it1!=it->second.end(); it1++){

std::cout<<*it;
}
std::cout<<std::endl;

}

Assuming

Pretty simple.

Leave a Comment