Exemple #1
0
void process(char* filename, mapT  &map)
{
	int nbWords=0;
	int nbUniqueWords=0;
	cout<<filename<<endl;
	fstream f;
	f.open(filename,  ios::in | ios::binary);
	if (f.bad())
	{
		f.close();
		throw "Could not open file";
	}

	f.unsetf(ios_base::skipws);

	char buffer[128]; 
	int pos=0;
	
	char c;
	int state=0;
	mapT::iterator it;

	while (!f.eof())
	{
		f>>c;
		if ( (c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='ç' || c=='ô' || 
			c=='è' || c=='ê' || c=='é' || c=='û' || c=='ù' || c=='à' || c=='â' || c=='î' || c=='ï')
		{
			state=1;
			buffer[pos]=c;
			pos++;
		} else 
		{
			if (pos>0) 
			{
				buffer[pos]=0;
				char* tmp = new char[pos+1];
				memcpy(tmp, buffer, pos+1);

				it=map.find(tmp);
				if (it==map.end())
				{ // new element
					map[tmp]=0;
					nbUniqueWords++;
				} else
				{
					map[tmp]++;
				}
				//cout<<buffer<<endl;
				pos=0; 
				nbWords++;
			}
			state=0;
		}
	};
	f.close();
	cout<<nbUniqueWords <<" unique words out of " <<nbWords<<" words."<<endl;
}
Exemple #2
0
 iterator find (const key_type& k) 
 { 
   wxMutexLocker lock(m_mutex);
   return map.find(k);
 }