Esempio n. 1
0
vector<string> HashTables::findMajorityWords_general(istringstream &sin, int k) {
    unordered_map<string, int> table;
    string s;
    int n=0;
    while (sin >> s) {
        table[s]++;
        n++;
        if (table.size()>=k+1) {
            for (auto it=table.begin(); it != table.end(); it++){
                if (--it->second==0) { // because it must be a item which is just added
                    table.erase(it++);
                }
            }
        }
    }

    for (auto &t:table)
        t.second=0;

    sin.clear();
    sin.seekg(0, ios::beg);
    while (sin>>s) {
        auto it = table.find(s);
        if (it != table.end())
            it->second++;
    }

    vector<string> ret;
    for (auto &t: table) {
        if (t.second>=static_cast<double>(n)/k)
            ret.emplace_back(t.first);
    }
    return ret;
}
const float& CPUPercentage::get_percentage()
{
  m_stat_file.open("/proc/stat");
  getline(m_stat_file, m_stat_line);
  m_stat_file.close();

  // skip "cpu"
  m_line_start_pos = m_stat_line.find_first_not_of(" ", 3);
  m_line_end_pos = m_stat_line.find_first_of(' ', m_line_start_pos);
  m_line_end_pos = m_stat_line.find_first_of(' ', m_line_end_pos + 1);
  m_line_end_pos = m_stat_line.find_first_of(' ', m_line_end_pos + 1);
  m_line_end_pos = m_stat_line.find_first_of(' ', m_line_end_pos + 1);
  m_iss.str(m_stat_line.substr(m_line_start_pos, m_line_end_pos - m_line_start_pos));
  m_iss >> m_next_user >> m_next_nice >> m_next_system >> m_next_idle;
  m_iss.clear();

  m_diff_user   = m_next_user - m_current_user;
  m_diff_system = m_next_system - m_current_system;
  m_diff_nice   = m_next_nice - m_current_nice;
  m_diff_idle   = m_next_idle - m_current_idle;
  m_percentage = static_cast<float>(m_diff_user + m_diff_system + m_diff_nice)/static_cast<float>(m_diff_user + m_diff_system + m_diff_nice + m_diff_idle)*100.0;

  m_current_user = m_next_user;
  m_current_system = m_next_system;
  m_current_nice = m_next_nice;
  m_current_idle = m_next_idle;

  return m_percentage;
}
Esempio n. 3
0
bool FirecrestInput::next_cluster( int *plane, int *ptile, int *px, int* py ) 
{
    string line ;
    if( !getline( intensities_, line ) ) return false ;
    cur_line_.str( line ) ;
    cur_line_.clear() ;
    cycle_ = 0 ;
    return cur_line_ >> *plane >> *ptile >> *px >> *py ; 
}
Esempio n. 4
0
inline void ObjIO::parseF(
    istringstream & line
,   ObjObject & object)
{
    ObjGroup & group = object.groups.empty() ? object : *object.groups.back();

    const e_FaceFormat format(parseFaceFormat(line));

    group.foffs.push_back(static_cast<GLuint>(group.vis.size()));

    GLuint i;

    while(line >> i)
    {
        group.vis.push_back(--i);

        switch(format)
        {
        case FF_V:  // v0 v1 ...

            break;

        case FF_VT: // v0/vt0 v1/vt1 ...

            line.ignore(1); // ignore slash
            line >> i;
            group.vtis.push_back(--i);

            break;
             
        case FF_VN: // v0//vn0 v1//vn1 ...

            line.ignore(2); // ignore slashes
            line >> i;
            group.vnis.push_back(--i);

            break;

        case FF_VTN: // v0/vt0/vn0 v1/vt1/vn1 ...

            line.ignore(1); // ignore slash
            line >> i;
            group.vtis.push_back(--i);

            line.ignore(1); // ignore slash
            line >> i;
            group.vnis.push_back(--i);

        default:
            break;
        }
    }
}
Esempio n. 5
0
void readConfig( istringstream& iss,
                 int& n_in,
                 int& n_out,
                 int& n_vocab,
                 int& n_project,
                 int& n_order,
                 float& momentum,
                 float& weight_decay,
                 float& alpha,
                 float& lnZ, 
                 string& norm_type, 
                 float& norm_param ) {
    n_in = 0;
    n_out = 0;
    n_vocab = 0;
    n_project = 0;
    n_order = 0;
    momentum = 0.0f;
    weight_decay = 0.0f;
    alpha = 0.0f;
    lnZ = 0.0f;
    norm_type = "none";
    norm_param = 10.0f;

    string token;
    while ( !iss.eof() ) {
        iss >> token;
        if ( token == "vocabulary" ) {
            iss >> n_vocab;
        }
        else if ( token == "projection" ) {
Esempio n. 6
0
result_t ValueListDataField::writeSymbols(istringstream& input,
		const unsigned char offset,
		SymbolString& output, const bool isMaster, unsigned char* usedLength)
{
	NumberDataType* numType = (NumberDataType*)m_dataType;
	if (isIgnored())
		return numType->writeRawValue(numType->getReplacement(), offset, m_length, output, usedLength); // replacement value

	const char* str = input.str().c_str();

	for (map<unsigned int, string>::iterator it = m_values.begin(); it != m_values.end(); it++)
		if (it->second.compare(str) == 0)
			return numType->writeRawValue(it->first, offset, m_length, output, usedLength);

	if (strcasecmp(str, NULL_VALUE) == 0)
		return numType->writeRawValue(numType->getReplacement(), offset, m_length, output, usedLength); // replacement value

	char* strEnd = NULL; // fall back to raw value in input
	unsigned int value;
	value = (unsigned int)strtoul(str, &strEnd, 10);
	if (strEnd == NULL || strEnd == str || (*strEnd != 0 && *strEnd != '.'))
		return RESULT_ERR_INVALID_NUM; // invalid value
	if (m_values.find(value) != m_values.end())
		return numType->writeRawValue(value, offset, m_length, output, usedLength);

	return RESULT_ERR_NOTFOUND; // value assignment not found
}
Esempio n. 7
0
void AgendaUI::createMeeting(void) {
    cout  << endl << "****************" << endl << "CreateMeeting"  << endl << "***************" << endl;
    os << "[create meeting] [title] [participator] [start time(yyyy-mm-dd/hh:mm)] [end time(yyy-mm-dd/hh:mm)]" << endl;
    os << "[create meeting] ";
    res = os.str();
    strcpy(buffer, res.c_str());
    os.str("");
    __send();
    __read();
    string title, participator, startDate, endDate;
    istringstream ss(is.str());
    ss >> title >> participator >> startDate >> endDate;

    cout << "!!!!!!!!" <<  title << participator << startDate << endDate << endl;
    if (agendaService_.createMeeting(userName_, title, participator, startDate, endDate)) {
        os << "[create meeting] succeed!" << endl;
        os << endl;
        os << "Agenda@" << userName_ << " : # ";
        res = os.str();
        strcpy(buffer, res.c_str());
        os.str("");
        __send();
        input();
    } else {
        os << "[error] create meeting fail!" << endl;
        os << endl;
        os << "Agenda@" << userName_ << " : # ";
        res = os.str();
        strcpy(buffer, res.c_str());
        os.str("");
        __send();
        input();
    }
}
Esempio n. 8
0
void Bank::createFromXml( istringstream& is, Program& program )
{
    Document doc;
    try
    {
	    doc.Parse( is.str(), true );
        Node* root = &doc;

        Node* programNode = doc.FirstChild( "Program", false );
        if( programNode != NULL ) {
            root = programNode;
        }

	    Iterator< Element > it( "Module" );
	    for( it = it.begin( root ); it != it.end(); it++ )
	    {
		    ModuleData* data = new ModuleData();
		    Element* moduleElement = it.Get();
		    readModule( moduleElement, data );

		    program.addModule( data );
	    }
    }
    catch( const exception& e ) {
        TRACE( e.what() );
    }
}
Esempio n. 9
0
void Bank::createFromXml( istringstream& is, ProgramList& list )
{
    Document doc;
    try
    {
	    doc.Parse( is.str(), true );

        Node* moduleNode = doc.FirstChild( "Module", false );
        if( moduleNode != NULL )
        {
            Program* program = new Program();
            createFromXml( is, *program );
            list.push_back( program );
        }
        else {

	        Iterator< Element > it( "Program" );
	        for( it = it.begin( &doc ); it != it.end(); it++ )
	        {
		        Program* program = new Program();
		        Element* programElement = it.Get();
		        readProgram( programElement, program );

		        list.push_back( program );
	        }
        }
    }
    catch( const exception& e ) {
        TRACE( e.what() );
    }
}
Esempio n. 10
0
static void parseQuotes(istringstream& result, forward_list<pair<string,quote_>>& quotes)
{
  string row;
  string date;
  float price[4];
  result.ignore(256, '\n');

  while(result.peek() != EOF)
  {
    getline(result, date, ',');
    result>> row;
    result.ignore();
    sscanf(row.c_str(), "%f,%f,%f,%f", &price[0], &price[1], &price[2], &price[3]);

    quotes.push_front(pair<string,quote_>(date, {price[0], price[1], price[2], price[3]}));
  }
}
Esempio n. 11
0
void __read() {
//    clntAddr.sin_family = AF_INET;
//    clntAddr.sin_port = htons(6666);
//    inet_pton(AF_INET, "20.1.0.60", &clntAddr.sin_addr);
    addrLen = sizeof(toAddr);
    clear_buffer();
    is.str("");
    cout << "__reading ...." << endl;
    if ((len = recvfrom(s, buffer, 2048, 0, (struct sockaddr*)&toAddr,&addrLen))<0) {
        cout << "shit" << endl;
    }
    printf("__read from  %s with the string:\n%s\n",inet_ntoa(toAddr.sin_addr), buffer);
    cout << "__read finished" << endl;
    cout << "the client enter : " << buffer << endl;
    string tem = buffer;
    cout << "the tem is " << tem << endl;
    is.str(tem);
}
Esempio n. 12
0
void TandemNativeParser::getPeaks(
  istringstream& tokenizer, ///< string version of values
  float* array,            ///< store values here
  int maxSize)              ///< array size
{
    // store values
    int curIdx = 0;
    while( !tokenizer.eof() ){
        assert(curIdx < maxSize);
        tokenizer >> array[curIdx];
        curIdx++;
    }
}
Esempio n. 13
0
string get(istringstream & in)
{
    while(true)
    {
        while(in.get()=='\"')
        {
            string result;
            char buf;
            while(true)
            {

                buf=in.get();
                if(buf=='\"')
                {
                    in.get();
                    return result;
                }
                result+=buf;
            }
        }
    }
}
Esempio n. 14
0
void AgendaUI::userLogIn(void) {
    cout  << endl << "****************" << endl << "login"  << endl << "***************" << endl;
    list<User> l = agendaService_.listAllUsers();
    if (l.empty()) {
        os << "[error] No User" << endl;
        res = os.str();
        strcpy(buffer, res.c_str());
        os.str("");
        __send();
        start_input();
        return;
    }
    os << endl;
    os << "[log in] [user name] [password]" << endl;
    os << "[log in] ";
    res = os.str();
    strcpy(buffer, res.c_str());
    os.str("");
    __send();
    __read();
    istringstream ss(is.str());
    ss >> userName_ >> userPassword_;

    // is >> userName_ >> userPassword_;
    cout << is.str() << endl;
    cout << "!!!!!!!!!" << userName_ << "   " << userPassword_ << endl;
    if (agendaService_.userLogIn(userName_, userPassword_)) {
        os << "[log in] succeed!" << endl;
        os << endl;
        help();
    } else {
        os << "[error] log in fail!" << endl;
        res = os.str();
        strcpy(buffer, res.c_str());
        os.str("");
        userLogIn();
    }
}
Esempio n. 15
0
bool OBJFile::ReadFace(istringstream& line){
    Face face;
    string vertex;

    while(!line.eof()){
        line >> vertex;
            vector<string> index;
            Split(vertex, index, "/");
            size_t current = strtoul(index[0].c_str(), NULL, 10)-1;
            face.Vertex.push_back(current);
    }
    m_faces.push_back(face);
    return true;

}
Esempio n. 16
0
//********************************************************************************************************************
//this function will jump over commented out sequences, but if the last sequence in a file is commented out it makes a blank seq
Sequence::Sequence(istringstream& fastaString){
	try {
		m = MothurOut::getInstance();
	
		initialize();
        name = getSequenceName(fastaString);
		
		if (!m->control_pressed) { 
			string sequence;
		
			//read comments
			while ((name[0] == '#') && fastaString) { 
				while (!fastaString.eof())	{	char c = fastaString.get(); if (c == 10 || c == 13){	break;	}	} // get rest of line if there's any crap there
				sequence = getCommentString(fastaString);
				
				if (fastaString) {  
					fastaString >> name;  
					name = name.substr(1);	
				}else { 
					name = "";
					break;
				}
			}
			
			//while (!fastaString.eof())	{	char c = fastaString.get();  if (c == 10 || c == 13){ break;	}	} // get rest of line if there's any crap there
            comment = getCommentString(fastaString);
			
			int numAmbig = 0;
			sequence = getSequenceString(fastaString, numAmbig);
			
			setAligned(sequence);	
			//setUnaligned removes any gap characters for us						
			setUnaligned(sequence);	
			
			if ((numAmbig / (float) numBases) > 0.25) { m->mothurOut("[WARNING]: We found more than 25% of the bases in sequence " + name + " to be ambiguous. Mothur is not setup to process protein sequences."); m->mothurOutEndLine(); }
		}
Esempio n. 17
0
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out","w",stdout);
#endif
scanf("%d\n",&cas);
tt=0;
while(cas--){
    printf("Case #%d: ",++tt);
    bases.clear();
    getline(cin,strtmp);
    inss.clear();
    inss.str(strtmp);
    while(inss>>a){
        bases.push_back(a);
    }
    j=2;
    while(!test(j)){
        j++;
    }
    printf("%d\n",j);
}
}
Esempio n. 18
0
int loadBodyFromModelLoader(::World* world, const char* name, const char *URL, istringstream &strm)
{
    vector<string> argvec;
    while (!strm.eof()){
        string arg;
        strm >> arg;
        argvec.push_back(arg);
    }
    int argc = argvec.size();
    char **argv = new char *[argc];
    for (int i=0; i<argc; i++){
        argv[i] = (char *)argvec[i].c_str();
    }

	int ret = loadBodyFromModelLoader(world, name, URL, argc, argv);

    delete [] argv;

    return ret;
}
Esempio n. 19
0
 NestedInteger deserialize(istringstream &in) {
 	int number;
     if(in>>number)	return NestedInteger(number); //如果开头是数字,那么一定是单个数的
     in.clear();
     in.get();
     NestedInteger list;
     while(in.peek() != ']')
     {
     	list.add(deserialize(in));
     	if(in.peek()==',')
     		in.get();
     }
     in.get();
     return list;
 }
Esempio n. 20
0
void AgendaUI::queryMeetingByTimeInterval(void) {
    cout  << endl << "****************" << endl << "queryMeetingByTimeInterval"  << endl << "***************" << endl;
    os << endl;
    os << "[query meetings] [start time(yyyy-mm-dd/hh:mm)] [end time(yyyy-mm-dd/hh:mm)]" << endl;
    os << "[query meeting] ";
    res = os.str();
    strcpy(buffer, res.c_str());
    os.str("");
    __send(),  __read();;
    std::string startDate, endDate;
    // is >> startDate >> endDate;
    istringstream ss(is.str());
    ss >> startDate >> endDate;
    cout << "!!!!!" << startDate << "   " << endDate << endl;
    os << endl;
    os << left << setw(17) << "title";
    os << left << setw(17) << "sponsor";
    os << left << setw(17) << "participator";
    os << left << setw(17) << "start time";
    os << left << setw(17) << "end time" << endl;
    list<Meeting> l = agendaService_.meetingQuery(userName_, startDate, endDate);
    for (list<Meeting>::iterator it = l.begin(); it != l.end(); it++) {
        os << left << setw(17) << it->getTitle();
        os << left << setw(17) << it->getSponsor();
        os << left << setw(17) << it->getParticipator();
        os << left << setw(17) << Date::dateToString(it->getStartDate());
        os << left << setw(17) << Date::dateToString(it->getEndDate()) << endl;
    }
    os << endl;
    os << endl;
    os << "Agenda@" << userName_ << " : # ";
    res = os.str();
    strcpy(buffer, res.c_str());
    os.str("");
    __send();
    input();
}
Esempio n. 21
0
inline const ObjIO::e_FaceFormat ObjIO::parseFaceFormat(const istringstream & line)
{
    string s(line.str());
    trim(s);

    size_t l(s.find(" "));
    if(string::npos == l)
        l = s.length();

    const size_t f0(s.find("/", 0));

    if(string::npos == f0)
        return FF_V;

    const size_t f1(s.find("/", f0 + 1));

    if(string::npos == f1 || f1 > l)
        return FF_VT;

    if(string::npos == s.find("//", 0))
        return FF_VTN;
    else
        return FF_VN;
}
Esempio n. 22
0
void AgendaUI::queryMeetingByTitle(void) {
    cout  << endl << "****************" << endl << "queryMeetingByTitle"  << endl << "***************" << endl;
    os << endl;
    os << "[query meeting] [title]:" << endl;
    os << "[query meeting] ";
    res = os.str();
    strcpy(buffer, res.c_str());
    os.str("");
    __send();
    __read();
    string title;
    istringstream ss(is.str());
    // is >> title;
    ss >> title;
    cout << "!!!!!!!!" << title << endl;
    os << endl;
    os << left << setw(17) << "sponsor";
    os << left << setw(17) << "participator";
    os << left << setw(17) << "start time";
    os << left << setw(17) << "end time" << endl;
    list<Meeting> l = agendaService_.meetingQuery(userName_, title);
    for (list<Meeting>::iterator it = l.begin(); it != l.end(); it++) {
        os << left << setw(17) << it->getSponsor();
        os << left << setw(17) << it->getParticipator();
        os << left << setw(17) << Date::dateToString(it->getStartDate());
        os << left << setw(17) << Date::dateToString(it->getEndDate()) << endl;
    }
    os << endl;
    os << endl;
    os << "Agenda@" << userName_ << " : # ";
    res = os.str();
    strcpy(buffer, res.c_str());
    os.str("");
    __send();
    input();
}
Esempio n. 23
0
			extSeq.setLastBase(dir, i);
			outseqs.push_back(extSeq);
		}
	}
}

/** Load k-mer with coverage data.
 * @return the number of k-mer loaded
 */
static size_t loadKmer(ISequenceCollection& g, FastaReader& in)
{
	assert(opt::rank == -1);
	size_t count = 0;
	for (FastaRecord rec; in >> rec;) {
		assert(rec.seq.size() == opt::kmerSize);
		istringstream iss(rec.id);
		float coverage = 1;
		iss >> coverage;
		assert(iss);
		assert(iss.eof());
		g.add(Kmer(rec.seq), max(1, (int)ceilf(coverage)));

		if (++count % 1000000 == 0) {
			logger(1) << "Read " << count << " k-mer. ";
			g.printLoad();
		}
		g.pumpNetwork();
	}
	assert(in.eof());
	return count;
}
		/// \brief TODOCUMENT
		void istreams_equal_test_suite_fixture::reset_stringstreams() {
			compare_ss.str        ( compare_str        );
			compare_ss_equal.str  ( compare_str_equal  );
			compare_ss_longer.str ( compare_str_longer );
			compare_ss_diff.str   ( compare_str_diff   );
		}
Esempio n. 25
0
	//loop to read all the data in from the file.
	while (getline(in, line)) //while there is still a line to be had.
	{
		if (line.substr(0,2) == "v ") //if it starts with "v " it is a vertex
		{
			istringstream s(line.substr(2));//read the info in through a stream.
			GLfloat x,y,z;//temp variables to hold the vertex data as it comes in.
			s >> x; s >> y; s >> z;//read in the vertex info
			verts.push_back(x);//push the info onto the vector
			verts.push_back(y);
			verts.push_back(z);
			vertc++;//increment the number of vertices.
		}
		else if (line.substr(0,2) == "f ") //if it starts with "f " it is a face.
		{
			istringstream s(line.substr(2));//stream in again for simplicity.
			GLushort a,b,c,d;//temp variables to hold face info as it comes in.
			s >> a; s >> b; s >> c;//read in the face info.
			a--; b--; c--;// each one needs to be decrememnted because .obj is 1 
				//indexed where as vbos are 0 indexed.
			els.push_back(a);//push info onto the vector
			els.push_back(b);
			els.push_back(c);
			elc++;//incrememnt the number of faces.
			char temp = s.peek();
			if ((int)temp != -1)
			{
				s >> d;
				d--;
				els.push_back(a);
				els.push_back(c);
Esempio n. 26
0
void assign(istringstream &iss, const string &str) {
	iss.clear();
	iss.str(str);
}
Esempio n. 27
0
string OBJLoader::readStr(istringstream &input) {
	return input.str().substr(1+input.tellg());
}