Пример #1
0
void add(MYMAP &m, std::pair<size_t , size_t> &p, const unsigned long int freq){
	MYMAP::iterator it = m.find(p); 
	if(it != m.end()){
		it->second += freq;
	}else{
		m.insert(MYPAIR(p , freq));
	}
};
Пример #2
0
int main()
{
  typedef  map< string , Student::Info , less<string> >  MYMAP;
  Student all[] =     { Student("Tom",111111,3.2),Student("Jack",222222,3.1),Student("Bob",33333,2.2),
    Student("Mike",44444,3.5)};
  MYMAP mp;
  for( int i = 0;i < 4; ++ i)
    mp.insert(make_pair(all[i].name,all[i].info));
  MYMAP::iterator i;
  for( i = mp.begin(); i != mp.end(); ++i ) {
    cout << i->first << "," << i->second.id << "," << i->second.gpa << endl;
  }
  return 0;
}
Пример #3
0
int main()
{
	typedef  multimap<string, Student::Info>  MYMAP;
	Student all[] = 
		{ Student("Tom",111111,3.2),Student("Jack",222222,3.1),Student("Bob",33333,2.2),Student("Mike",44444,3.5)};

	MYMAP mp;
	for( int i = 0;i < 4; ++ i)
		mp.insert(MYMAP::value_type(all[i].name, all[i].info)) ;
	MYMAP::iterator i;
	for( i = mp.begin(); i != mp.end(); ++i ) {
		cout << i->first << "," << i->second.id << "," << i->second.gpa << endl;
	}
	system("pause");
	return 0;
}
Пример #4
0
void printout(const int ngram, MYMAP &m, const std::string &out_folder, const char* buf, const unsigned int SKIP){
	std::stringstream ss;
	ss << out_folder << "/" << ngram << "gms/";
	yucha::tool::recursive_mkdir(ss.str().c_str());

	//Print out the result
	{
		size_t count = 0;
		size_t filenum = 0;
//                std::ofstream *ret = new std::ofstream(getOutName(ss.str(), ngram, filenum).c_str());
		FILE *ret = fopen(getOutName(ss.str(), ngram, filenum).c_str(), "w" );

		for(MYMAP::const_iterator it = m.begin(); it != m.end(); ++it){
			++count;
			if (SKIP != 0 and count % SKIP == 0){
				++filenum;
//                                ret->close();
//                                delete ret;
//                                ret = new std::ofstream(getOutName(ss.str(), ngram, filenum).c_str());
				fclose(ret);
				ret = fopen(getOutName(ss.str(), ngram, filenum).c_str(), "w" );
			}

//                        std::string s(buf + it->first.first , buf + it->first.second);
//                        *ret << s << "\t" << it->second << std::endl;
			for(size_t j=it->first.first; j<it->first.second; ++j){
				fputc(buf[j], ret);
			};
			fputc('\t', ret);
			fprintf(ret,"%lu", it->second);
			fputc('\n', ret);
		};
				fclose(ret);
//                ret->close();
//                delete ret;
	}
};