//--------------------------------------------------------------------------- const char* StringValue( const unsigned int stringID ) { const char* errorValue = "empty!"; StringTable::iterator iter; for ( iter = s_theStringTable.begin(); iter != s_theStringTable.end(); ++ iter ) { if ( iter->second.m_id == stringID ) return iter->second.m_originalString.c_str(); } return errorValue; }
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()); }
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; } }
bool WriteStrings(ostream& out, const string& header, StringTable& strings, bool escape) { out << "[" << header << "]" << std::endl; for (StringTable::iterator iter = strings.begin(); iter != strings.end(); iter++) { out << iter->first << "="; if (escape) out << Escape(iter->second); else out << iter->second; out << std::endl; } return true; }
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()); } } }