示例#1
0
static void CountOccurrences(int nthreads) {
    StringTable table;

    tick_count t0 = tick_count::now();
    parallel_for( blocked_range<mystring*>( Data, Data+N, 1000 ), Tally(table) );
    tick_count t1 = tick_count::now();

    int n = 0;
    for( StringTable::iterator i=table.begin(); i!=table.end(); ++i ) {
        if( Verbose && nthreads )
            printf("%s %d\n",i->first.c_str(),i->second);
        n += i->second;
    }

    if (is_number_of_threads_set) {
        printf("threads = %d  total = %d  unique = %u  time = %g\n", nthreads, n, unsigned(table.size()), (t1-t0).seconds());
    } else {
        if ( nthreads == 1 ) {
            printf("serial run   total = %d  unique = %u  time = %g\n", n, unsigned(table.size()), (t1-t0).seconds());
        } else {
            printf("parallel run total = %d  unique = %u  time = %g\n", n, unsigned(table.size()), (t1-t0).seconds());
        }
    }
}
static void CountOccurrences(int nthreads) {
    StringTable table;

    tick_count t0 = tick_count::now();
    parallel_for( blocked_range<MyString*>( Data, Data+N, 1000 ), Tally(table) );
    tick_count t1 = tick_count::now();

    int n = 0;
    for( StringTable::iterator i=table.begin(); i!=table.end(); ++i ) {
        if( verbose && nthreads )
            printf("%s %d\n",i->first.c_str(),i->second);
        n += i->second;
    }

    if ( !silent ) printf("total = %d  unique = %u  time = %g\n", n, unsigned(table.size()), (t1-t0).seconds());
}
示例#3
0
    void Save(const char* filename)
    {
        const std::string header("String #");
        const std::string header_next(" is ");
        const char splitter = '~';

        if(_origin.empty())
            return;

        std::ofstream  fin(filename);

        fin << "// Total:" << _origin.size() << std::endl;
        StringTable::iterator itr = _origin.begin();
        for(;itr!=_origin.end();itr++)
        {
            fin << header << itr->first << header_next << splitter
                << itr->second << splitter << std::endl;
        }
    }
示例#4
0
bool ItemReader::readItems(std::map<std::string, ItemBean>& itemMap) const
{
	itemMap.clear();
	wstring contents = getFileContentsWide(g_resourceManager->getFilename(ResourceID::Items));
	if (contents.empty())
	{
		return false;
	}
	StringTable tab;
	parseCsv((wchar_t *)contents.c_str(), tab);
	if (tab.size() == 0 || tab[0].size() != COLUMN_COUNT)
	{
		g_logger->logError("ItemReader", "Error in item file, incorrect number of columns or no rows");
		return false;
	}
	
	int lineNr = 0;
	for (auto &row : tab)
	{
		lineNr++;
		if (lineNr == 1)
		{
			// we skip the first row as it is a description of the colums (title row)
			continue;
		}
		ItemBean item = DEFAULT_ITEM;
		vector<string> columns;
		for (auto &col : row)
		{
			columns.push_back(string(col.begin(), col.end()));
		}

		while (columns.size() < COLUMN_COUNT)
		{
			columns.push_back("");
		}

		if (columns.size() != COLUMN_COUNT)
		{
			g_logger->logError("ItemReader", "Error in item file, incorrect number of columns");
			return false;
		}

		// <<<<<<<< PARSE >>>>>>>>>

		// item id
		item.id = columns[0];
		// item description
		item.description = columns[1];
		// item type
		item.type = static_cast<ItemType>(atoi(columns[2].c_str()));
		// icon texture location
		if (!columns[3].empty() && columns[3].find(",") != string::npos && columns[3].find(",") + 1 < columns[3].size())
		{
			item.iconTextureLocation.x = atoi(columns[3].c_str());
			item.iconTextureLocation.y = atoi(columns[3].substr(columns[3].find(",") + 1).c_str());
		}
		// gold value
		item.goldValue = atoi(columns[4].c_str());
		// attributes
		item.attributes.maxHealthPoints = atoi(columns[5].c_str());
		item.attributes.healthRegenerationPerS = atoi(columns[6].c_str());
		item.attributes.haste = atoi(columns[7].c_str());
		item.attributes.critical = atoi(columns[8].c_str());
		item.attributes.damagePhysical = atoi(columns[9].c_str());
		item.attributes.damageFire = atoi(columns[10].c_str());
		item.attributes.damageIce = atoi(columns[11].c_str());
		item.attributes.damageShadow = atoi(columns[12].c_str());
		item.attributes.damageLight = atoi(columns[13].c_str());
		item.attributes.resistancePhysical = atoi(columns[14].c_str());
		item.attributes.resistanceFire = atoi(columns[15].c_str());
		item.attributes.resistanceIce = atoi(columns[16].c_str());
		item.attributes.resistanceShadow = atoi(columns[17].c_str());
		item.attributes.resistanceLight = atoi(columns[18].c_str());
		// food duration
		item.foodDuration = sf::seconds(static_cast<float>(atoi(columns[19].c_str())));
		// sprite offset
		if (!columns[20].empty() && columns[20].find(",") != string::npos && columns[20].find(",") + 1 < columns[20].size())
		{
			item.spriteOffset.x = static_cast<float>(atoi(columns[20].c_str()));
			item.spriteOffset.y = static_cast<float>(atoi(columns[20].substr(columns[20].find(",") + 1).c_str()));
		}
		// level item bounding box
		if (!columns[21].empty())
		{
			std::stringstream ss(columns[21]);
			int i;
			vector<float> boundingBoxValues;
			while (ss >> i)
			{
				boundingBoxValues.push_back(static_cast<float>(i));

				if (ss.peek() == ',' || ss.peek() == ' ')
					ss.ignore();
			}
			if (boundingBoxValues.size() != 2)
			{
				g_logger->logError("ItemReader", "Level Item Bounding box could not be parsed!");
				return false;
			}
			item.boundingBox.left = 0;
			item.boundingBox.top = 0;
			item.boundingBox.width = boundingBoxValues[0];
			item.boundingBox.height = boundingBoxValues[1];
		}
		// level item texture position(s)
		if (!columns[22].empty())
		{
			std::stringstream ss(columns[22]);
			int i;
			vector<int> texturePositions;
			while (ss >> i)
			{
				texturePositions.push_back(i);

				if (ss.peek() == ',' || ss.peek() == ' ')
					ss.ignore();
			}
			if (texturePositions.size() % 4 != 0)
			{
				g_logger->logError("ItemReader", "Level Item texture positions could not be parsed!");
				return false;
			}

			for (int val = 0; val < texturePositions.size();)
			{
				sf::IntRect texturePosition;
				texturePosition.left = texturePositions[val++];
				texturePosition.top = texturePositions[val++];
				texturePosition.width = texturePositions[val++];
				texturePosition.height = texturePositions[val++];
				item.texturePositions.push_back(texturePosition);
			}
		}