当前位置: 首页>>代码示例>>C++>>正文


C++ map::size方法代码示例

本文整理汇总了C++中map::size方法的典型用法代码示例。如果您正苦于以下问题:C++ map::size方法的具体用法?C++ map::size怎么用?C++ map::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在map的用法示例。


在下文中一共展示了map::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

void
setupNextSubsession(RTSPClient* rtspClient) {
	UsageEnvironment& env = rtspClient->envir(); // alias
	StreamClientState& scs = ((ourRTSPClient*)rtspClient)->scs; // alias
	bool rtpOverTCP = false;

	if(rtspconf->proto == IPPROTO_TCP) {
		rtpOverTCP = true;
	}

	scs.subsession = scs.iter->next();
	do if (scs.subsession != NULL) {
		if (!scs.subsession->initiate()) {
			env << *rtspClient << "Failed to initiate the \"" << *scs.subsession << "\" subsession: " << env.getResultMsg() << "\n";
			setupNextSubsession(rtspClient); // give up on this subsession; go to the next one
		} else {
			if(strcmp("video", scs.subsession->mediumName()) == 0) {
				video_sess_fmt = scs.subsession->rtpPayloadFormat();
				video_codec_name = strdup(scs.subsession->codecName());
				if(port2channel.find(scs.subsession->clientPortNum()) == port2channel.end()) {
					int cid = port2channel.size();
					port2channel[scs.subsession->clientPortNum()] = cid;
#ifdef ANDROID
					if(rtspconf->builtin_video_decoder != 0) {
						video_codec_id = ga_lookup_codec_id(video_codec_name);
					} else {
					////// Work with ffmpeg
#endif
					if(init_vdecoder(cid, scs.subsession->fmtp_spropparametersets()) < 0) {
						rtsperror("cannot initialize video decoder(%d)\n", cid);
						rtspParam->quitLive555 = 1;
						return;
					}
					rtsperror("video decoder(%d) initialized (client port %d)\n",
						cid, scs.subsession->clientPortNum());
#ifdef ANDROID
					////////////////////////
					}
#endif
				}
			} else if(strcmp("audio", scs.subsession->mediumName()) == 0) {
				const char *mime = NULL;
				audio_sess_fmt = scs.subsession->rtpPayloadFormat();
				audio_codec_name = strdup(scs.subsession->codecName());
#ifdef ANDROID
				if((mime = ga_lookup_mime(audio_codec_name)) == NULL) {
					showToast(rtspParam->jnienv, "codec %s not supported", audio_codec_name);
					rtsperror("rtspclient: unsupported audio codec: %s\n", audio_codec_name);
					usleep(300000);
					rtspParam->quitLive555 = 1;
					return;
				}
				audio_codec_id = ga_lookup_codec_id(audio_codec_name);
				if(android_prepare_audio(rtspParam, mime, rtspconf->builtin_audio_decoder != 0) < 0)
					return;
				if(rtspconf->builtin_audio_decoder == 0) {
				//////////////////////////////////////
				rtsperror("init software audio decoder.\n");
#endif
				if(adecoder == NULL) {
					if(init_adecoder() < 0) {
						rtsperror("cannot initialize audio decoder.\n");
						rtspParam->quitLive555 = 1;
						return;
					}
				}
#ifdef ANDROID
				//////////////////////////////////////
				}
#endif
				rtsperror("audio decoder initialized.\n");
			}
			env << *rtspClient << "Initiated the \"" << *scs.subsession
				<< "\" subsession (client ports " << scs.subsession->clientPortNum() << "-" << scs.subsession->clientPortNum()+1 << ")\n";

			// Continue setting up this subsession, by sending a RTSP "SETUP" command:
			rtspClient->sendSetupCommand(*scs.subsession, continueAfterSETUP, False, rtpOverTCP ? True : False/*TCP?*/, False, NULL);
		}
		return;
	} while(0);
	//

	// We've finished setting up all of the subsessions.  Now, send a RTSP "PLAY" command to start the streaming:
	scs.duration = scs.session->playEndTime() - scs.session->playStartTime();
	rtspClient->sendPlayCommand(*scs.session, continueAfterPLAY);
}
开发者ID:sabbath0208,项目名称:gaminganywhere,代码行数:86,代码来源:rtspclient.cpp

示例2: AfterReadingFiles

//------------------------------------------------------------------------------------
int AfterReadingFiles(int reading) throw(Exception)
{
try {
   int i,j,iret=0;

   if(reading == 1) {

         // compute data interval for this file
      for(j=0,i=1; i<9; i++) { if(PIC.ndt[i]>PIC.ndt[j]) j=i; }
      PIC.DT = PIC.estdt[j];
      PIC.oflog << endl;
      PIC.oflog << "Estimated data interval is " << PIC.DT << " seconds.\n";
      PIC.oflog << "Interpolate to " << PIC.irate << " times the input data rate\n";
      PIC.oflog << "Last data epoch is "
         << printTime(PIC.LastEpoch,"%04Y/%02m/%02d %02H:%02M:%06.3f = %4F %.3g") << endl;

      if(TimePositionMap.size() == 0) {
         cout << "No position information was found in the input file! Abort.\n";
         PIC.oflog << "No position information was found in the input file! Abort.\n";
         return -1;
      }
      PIC.oflog << endl;

         // dump the map of positions
      if(PIC.DumpMap) {
         PIC.oflog << "Here is all the Time/Position information:\n";
         map<CommonTime,PosInfo>::const_iterator itr;
         itr = TimePositionMap.begin();
         i = 0;
         while(itr != TimePositionMap.end()) {
            PIC.oflog << setw(4) << i << " "
               << printTime((itr->first),"%04Y/%02m/%02d %02H:%02M:%6.3f %4F %10.3g")
               << fixed << setprecision(3)
               << " " << setw(2) << itr->second.N
               << " " << setw(13) << itr->second.X
               << " " << setw(13) << itr->second.Y
               << " " << setw(13) << itr->second.Z
               << " " << setw(13) << itr->second.T
               << " " << setw(7) << itr->second.rms
               << endl;
            itr++;
            i++;
         }
         PIC.oflog << "End of the Time/Position information.\n\n";
      }

         // open output file
      if(!PIC.OutRinexObs.empty()) {
         ofstr.open(PIC.OutRinexObs.c_str(), ios::out);
         if(ofstr.fail()) {
            PIC.oflog << "Failed to open output file " << PIC.OutRinexObs
               << ". Abort.\n";
            return 1;
         }
         else PIC.oflog << "Opened output file " << PIC.OutRinexObs << endl;
         ofstr.exceptions(ios::failbit);
      }
   }
   else if(reading==2) {
      PIC.oflog << "Close the output file\n";
      ofstr.close();
   }

   return iret;
}
catch(Exception& e) { GPSTK_RETHROW(e); }
catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }
catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); }
}
开发者ID:JC5005,项目名称:GPSTk,代码行数:70,代码来源:posInterp.cpp

示例3: strName

CScript
ParseScript(string s)
{
    CScript result;

    static map<string, opcodetype> mapOpNames;

    if (mapOpNames.size() == 0)
    {
        for (int op = OP_NOP; op <= OP_NOP10; op++)
        {
            const char* name = GetOpName((opcodetype)op);
            if (strcmp(name, "OP_UNKNOWN") == 0)
                continue;
            string strName(name);
            mapOpNames[strName] = (opcodetype)op;
            // Convenience: OP_ADD and just ADD are both recognized:
            replace_first(strName, "OP_", "");
            mapOpNames[strName] = (opcodetype)op;
        }
    }

    vector<string> words;
    split(words, s, is_any_of(" \t\n"), token_compress_on);

    BOOST_FOREACH(string w, words)
    {
        if (all(w, is_digit()) ||
            (starts_with(w, "-") && all(string(w.begin()+1, w.end()), is_digit())))
        {
            // Number
            int64 n = atoi64(w);
            result << n;
        }
        else if (starts_with(w, "0x") && IsHex(string(w.begin()+2, w.end())))
        {
            // Raw hex data, inserted NOT pushed onto stack:
            std::vector<unsigned char> raw = ParseHex(string(w.begin()+2, w.end()));
            result.insert(result.end(), raw.begin(), raw.end());
        }
        else if (w.size() >= 2 && starts_with(w, "'") && ends_with(w, "'"))
        {
            // Single-quoted string, pushed as data. NOTE: this is poor-man's
            // parsing, spaces/tabs/newlines in single-quoted strings won't work.
            std::vector<unsigned char> value(w.begin()+1, w.end()-1);
            result << value;
        }
        else if (mapOpNames.count(w))
        {
            // opcode, e.g. OP_ADD or OP_1:
            result << mapOpNames[w];
        }
        else
        {
            BOOST_ERROR("Parse error: " << s);
            return CScript();
        }                        
    }

    return result;
}
开发者ID:an420,项目名称:420,代码行数:61,代码来源:script_tests.cpp

示例4: TestParallelThreads

void TestParallelThreads( map<int, string> &userspace_cpu, vector<string> &freq_event, int samplings, int thread_count ) {
    int rc;
    void *status;

    string err;

    if( userspace_cpu.size() < 1 ) {
        printf( "Insufficient CPUs available for threading test\n" );
        return;
    }

    printf( "Using %d processors\n", (int)userspace_cpu.size() );

    int node_count = 1000;
    map<int, string> cpu_avail_freq;
    map<int, string>::iterator cpu_it;

    map<int, string>::iterator freq_it;

    int max_threads = thread_count * userspace_cpu.size();

    pthread_t threads[max_threads];
    cpu_set_t cpus[max_threads];
    cpu_set_t check_cpu;
    pthread_attr_t thread_attrs[max_threads];

    throt_ctrl_t throts[max_threads];

    int max_time_lapse = -1, tmp_lapse;

    printf("# filling available throttling speeds\n");
    fillAvailableThrottlingSpeeds( cpu_avail_freq, 1 );
    int i, j, idx;

    // initialize thread attributes with cpu affinity
    // initialize throttling controls
    idx = 0;

//    for(idx = 0; idx < max_threads; idx++) {
//        CPU_ZERO( &cpus[idx]);
//    }
//
//    for(cpu_it = userspace_cpu.begin(); cpu_it != userspace_cpu.end(); cpu_it++) {
//        for(idx = 0; idx < max_threads; idx++) {
//            CPU_SET( cpu_it->first, &cpus[idx]);
//        }
//    }

    idx = 0;
    for( cpu_it = userspace_cpu.begin(), i = 0; cpu_it != userspace_cpu.end(); cpu_it++, i++ ) {
        for(j = 0; j < thread_count; ++j, ++idx) {
            CPU_ZERO( &cpus[idx] );
            CPU_SET( cpu_it->first, &cpus[idx] );
            pthread_attr_init( &thread_attrs[idx] );
//            pthread_attr_setscope(&thread_attrs[idx], PTHREAD_SCOPE_SYSTEM);   // explicitly state the each thread is its own process; (END result - no effect from either scope; something must be overriding)

            int val = pthread_attr_setaffinity_np( &thread_attrs[idx], sizeof( cpu_set_t ), &cpus[idx] );

            if( val ) {
                printf( "Set Affinity Fail: %s\n", strerror(val) );
            }
            pthread_attr_setdetachstate( &thread_attrs[idx], PTHREAD_CREATE_DETACHED ); // make thread detachable
//            pthread_attr_setschedpolicy( &thread_attrs[idx], SCHED_RR);
//            throts[idx].root = new node_t();
//            generateCircularGraph( throts[idx].root, node_count );


            throts[idx].cpu_id = cpu_it->first;
            throts[idx].node_count = node_count;
    //        ctrl_event_t ctrl1, ctrl2;
    //
    //        freq_it = cpu_avail_freq.begin();
    //        ctrl1.throt_speed = freq_it->second;
    //        ctrl2.throt_speed = cpu_avail_freq.rbegin()->second;
    //
    //        if( cpu_it->first  % 4 ) {
    //            throts[i].events.push_back( ctrl1 );
    //            throts[i].events.push_back( ctrl1 );
    //        } else {
    //            throts[i].events.push_back( ctrl1 );
    //            throts[i].events.push_back( ctrl2 );
    //        }

            tmp_lapse = buildEvents(freq_event, idx, cpu_avail_freq, throts[idx].events);
            if(max_time_lapse < tmp_lapse) {
                max_time_lapse = tmp_lapse;
            }
        }
    }

    TIME t1;
    timespec t;

    for( int samp = 0; samp < samplings; ++samp ) {
        printf( "Sampling...%d\n", samp );
        idx = 0;
        for( cpu_it = userspace_cpu.begin(), i = 0; cpu_it != userspace_cpu.end(); cpu_it++, i++ ) {
            for(j = 0; j < thread_count; ++j, ++idx) {
                if( rc = pthread_create( &threads[idx], &thread_attrs[idx], EventThreads, ( void * ) &throts[idx] ) ) {
                    printf( "Error creating threads\n" );
//.........这里部分代码省略.........
开发者ID:wilseypa,项目名称:softFrequencyControl,代码行数:101,代码来源:throt_4.cpp

示例5: S_Read_SNDSEQ


//.........这里部分代码省略.........
		    temp.data.push_back(S_GetSoundID(line));
		    temp.data.push_back(SSEQ_WAITUNTILDONE);
		  }
		break;

	      case SSEQ_PLAYTIME:
		if (p.GetString(line, 32))
		  {
		    temp.data.push_back(SSEQ_PLAY);
		    temp.data.push_back(S_GetSoundID(line));
		    temp.data.push_back(SSEQ_DELAY);
		    temp.data.push_back(p.GetInt());
		  }

	      case SSEQ_PLAYREPEAT:
		if (p.GetString(line, 32))
		  {
		    temp.data.push_back(SSEQ_PLAYREPEAT);
		    temp.data.push_back(S_GetSoundID(line));
		  }
		break;

	      case SSEQ_DELAY:
		temp.data.push_back(SSEQ_DELAY);
		temp.data.push_back(p.GetInt());
		break;

	      case SSEQ_DELAYRAND:
		temp.data.push_back(SSEQ_DELAYRAND);
		temp.data.push_back(p.GetInt());
		temp.data.push_back(p.GetInt());
		break;

	      case SSEQ_VOLUME:
		temp.data.push_back(SSEQ_VOLUME);
		temp.data.push_back(p.GetInt());
		break;

	      case SSEQ_STOPSOUND:
		if (p.GetString(line, 32))
		  {
		    temp.data.push_back(SSEQ_STOPSOUND);
		    temp.stopsound = S_GetSoundID(line);
		  }
		break;

	      case SSEQ_END:
		temp.data.push_back(SSEQ_END);

		// create and store the sequence
		if (SoundSeqs.count(temp.number)) // already there
		  {
		    CONS_Printf("Warning: Sequence %d defined more than once!\n", temp.number);
		    delete SoundSeqs[temp.number]; // later one takes precedence
		  }

		ss = new sndseq_t(temp); // make a copy
		SoundSeqs[ss->number] = ss; // insert into the map

		//CONS_Printf(" seq %d done\n", ss->number);

		if (hseq >= 0)
		  { // other half of the Hexen kludge:
		    // some sequences need to be copied
		    for (n=1; n<3; n++)
		      if (HexenSeqs[hseq].seq[n] != -1)
			{
			  ss = new sndseq_t(temp);
			  ss->number = HexenSeqs[hseq].seq[n];
			  SoundSeqs[ss->number] = ss;
			  //CONS_Printf(" seq %d done\n", ss->number);
			}
		    
		    hseq = -1;
		  }

		temp.number = -1;
		break;

	      case SSEQ_VOLUMERAND:
		temp.data.push_back(SSEQ_VOLUMERAND);
		temp.data.push_back(p.GetInt());
		temp.data.push_back(p.GetInt());
		break;

	      case SSEQ_CHVOL:
		temp.data.push_back(SSEQ_CHVOL);
		temp.data.push_back(p.GetInt());
		break;

	      default:
		CONS_Printf("Unknown command '%s'.\n", line);
		break;
	      }
	}
    }

  CONS_Printf(" %d sequences found.\n", SoundSeqs.size());
  return SoundSeqs.size();
}
开发者ID:meiavy,项目名称:doom-legacy,代码行数:101,代码来源:s_sndseq.cpp

示例6: select_parameters

    bool ChooserEvaluator::select_parameters(
        const std::vector<ChooserPoly> &operands, 
        int budget_gap, double noise_standard_deviation, 
        const map<int, vector<SmallModulus> > &coeff_modulus_options, 
        EncryptionParameters &destination)
    {
        if (budget_gap < 0)
        {
            throw std::invalid_argument("budget_gap cannot be negative");
        }
        if (noise_standard_deviation < 0)
        {
            throw invalid_argument("noise_standard_deviation can not be negative");
        }
        if (coeff_modulus_options.size() == 0)
        {
            throw invalid_argument("parameter_options must contain at least one entry");
        }
        if (operands.empty())
        {
            throw invalid_argument("operands cannot be empty");
        }

        int largest_bit_count = 0;
        int largest_coeff_count = 0;
        for (size_t i = 0; i < operands.size(); i++)
        {
            if (operands[i].comp_ == nullptr)
            {
                throw logic_error("no operation history to simulate");
            }
            int current_bit_count = get_significant_bit_count(operands[i].max_abs_value_);
            largest_bit_count = (current_bit_count > largest_bit_count) ? 
                current_bit_count : largest_bit_count;

            int current_coeff_count = operands[i].max_coeff_count_;
            largest_coeff_count = (current_coeff_count > largest_coeff_count) ? 
                current_coeff_count : largest_coeff_count;
        }

        // We restrict to plain moduli that are powers of two. Here largest_bit_count 
        // is the largest positive coefficient that we can expect to appear. Thus, we 
        // need one more bit.
        uint64_t new_plain_modulus;
        if (largest_bit_count >= SEAL_USER_MODULO_BIT_BOUND)
        {
            // The plain_modulus needed is too big
            return false;
        }
        new_plain_modulus = 1ULL << largest_bit_count;
        destination.set_plain_modulus(new_plain_modulus);

        bool found_good_parms = false;
        map<int, vector<SmallModulus> >::const_iterator iter = coeff_modulus_options.begin();
        while (iter != coeff_modulus_options.end() && !found_good_parms)
        {
            int dimension = iter->first;
            if (dimension < 512 || (dimension & (dimension - 1)) != 0)
            {
                throw invalid_argument("coeff_modulus_options keys invalid");
            }

            int coeff_bit_count = 0;
            for(auto mod : iter->second)
            {
                coeff_bit_count += mod.bit_count();
            }

            if (dimension > largest_coeff_count && 
                coeff_bit_count > destination.plain_modulus().bit_count())
            {
                // Set the polynomial
                destination.set_coeff_modulus(iter->second);
                BigPoly new_poly_modulus(dimension + 1, 1);
                new_poly_modulus.set_zero();
                new_poly_modulus[0] = 1;
                new_poly_modulus[dimension] = 1;
                destination.set_poly_modulus(new_poly_modulus);

                // The bound needed for GapSVP->search-LWE reduction
                //parms.noise_standard_deviation() = round(sqrt(dimension / (2 * 3.1415)) + 0.5);

                // Use constant (small) standard deviation.
                destination.set_noise_standard_deviation(noise_standard_deviation);

                found_good_parms = true;
                for (size_t i = 0; i < operands.size(); i++)
                {
                    // If one of the operands does not decrypt, set found_good_parms to false.
                    found_good_parms = operands[i].simulate(destination).decrypts(budget_gap) ? 
                        found_good_parms : false;
                }
            }

            // This dimension/coeff_modulus are to small. Move on to the next pair.
            iter++;
        }

        if (!found_good_parms)
        {
//.........这里部分代码省略.........
开发者ID:deeptechlabs,项目名称:SEAL,代码行数:101,代码来源:chooser.cpp

示例7: runShell

/*
 * Runs the program in command shell mode, listening for commands until the user exits
 */
void runShell(){
	bool exit = false;
	while (!exit) {
		vector<string> args;
		cout << "==>" ;
		string line;
		cin.clear();

		//Get line and convert to vector
		getline(cin, line);
		istringstream input (line);
		string word;
		vector<string> list;
		while(input >> word){
			list.push_back(word);
			if (word == "exit" && list.size() == 1){
				exit = true;
			}
		}

		if(exit){
			//Check if background processes are running
			if( running.size() == 0)
				break;
			else{
			
			cout << "There are processes running, please wait before exiting\n";
			exit = false;
			}
		}else if (list.size() < 1){
			//Do nothing
		}else if(list[0] == "cd"){
			//Change directory

			if (chdir(list[1].c_str()) < 0){
				cerr << "Error changing directory\n";
			}
		}else if(list[0] == "jobs"){

			printJobs();
		}else {
			//copy args
			char *newargs[list.size() + 1];
			for(int i = 0; i < (int)list.size(); i++){
				newargs[i] = (char *)list[i].c_str();
			} 
			newargs[list.size()] = 0;

			//remove & if it is in the list
			bool back = false;
			if(newargs[list.size() -1][0] ==  '&'){
				newargs[list.size() -1 ] = 0;
				back = true;
			}
			int pid = runCommand(newargs);
			if(back){
				//Setup task as background task
				struct timeval astart;
				gettimeofday(&astart, NULL);
				process p = {pid, newargs[0], timevalToMs(astart), running.size()+1};
				running[pid] = p;
				cout << "[" << running.size() << "] " << pid << "\n";
			}else{
				//wait and get stats
				getStats(-1, pid);
			}
		}
		list.clear();

	}
}
开发者ID:lhunker,项目名称:cs3013-proj1,代码行数:74,代码来源:doit.cpp

示例8:

		Filter(string className){
			cerr<<className<<endl;
			filterManager.insert(make_pair(className,this));
			cerr<<filterManager.size()<<endl;
		}
开发者ID:LiChungYi,项目名称:dp-final-project,代码行数:5,代码来源:Filter.hpp

示例9: generic_request_handler

void generic_request_handler(struct evhttp_request *req, void *arg)
{
    struct evbuffer *returnbuffer = evbuffer_new();
	evhttp_add_header(req->output_headers, "Content-Type", "text/html; charset=UTF-8");
    evhttp_add_header(req->output_headers, "Server", "conn_test_server");
    evhttp_add_header(req->output_headers, "Connection", "close");
	
	evbuffer_add_printf(returnbuffer, "<html><head><title>conn_test_server</title>");

	evbuffer_add_printf(returnbuffer, "<meta http-equiv=\"refresh\" content=\"%d\"/>", 1);

	evbuffer_add_printf(returnbuffer, "</head><body>");

	evbuffer_add_printf(returnbuffer, "<font size=\"24px\">");
	evbuffer_add_printf(returnbuffer, "<table align=\"center\">");
	evbuffer_add_printf(returnbuffer, "<tr><td><font size=\"24px\">Connections:</font></td><td><strong><font color=\"blue\" size=\"24px\">%u</font></strong></td></tr>", (unsigned int)g_conns.size());
#ifndef WIN32
	evbuffer_add_printf(returnbuffer, "<tr><td><font size=\"24px\">Total Flow:</font></td><td><strong><font color=\"blue\" size=\"24px\">%lluB</font></strong></td></tr>", g_new_flow);
#else
	evbuffer_add_printf(returnbuffer, "<tr><td><font size=\"24px\">Total Flow:</font></td><td><strong><font color=\"blue\" size=\"24px\">%I64uB</font></strong></td></tr>", g_new_flow);
#endif
	evbuffer_add_printf(returnbuffer, "<tr><td><font size=\"24px\">Total Speed:</font></td><td><strong><font color=\"blue\" size=\"24px\">%f%s</font></strong></td></tr>", g_flow_speed, g_flow_speed_unit);
	evbuffer_add_printf(returnbuffer, "</table>");
	evbuffer_add_printf(returnbuffer, "</font>");
    evbuffer_add_printf(returnbuffer, "</body></html>");
    evhttp_send_reply(req, HTTP_OK, "Client", returnbuffer);
    evbuffer_free(returnbuffer);
    return;
}
开发者ID:wdj729115299,项目名称:conn_test,代码行数:29,代码来源:main.cpp

示例10: runAMOVA

double AmovaCommand::runAMOVA(ofstream& AMOVAFile, map<string, vector<int> > groupSampleMap, double alpha) {
	try {
		map<string, vector<int> >::iterator it;

		int numGroups = groupSampleMap.size();
		int totalNumSamples = 0;

		for(it = groupSampleMap.begin();it!=groupSampleMap.end();it++){
			totalNumSamples += it->second.size();			
		}

		double ssTotalOrig = calcSSTotal(groupSampleMap);
		double ssWithinOrig = calcSSWithin(groupSampleMap);
		double ssAmongOrig = ssTotalOrig - ssWithinOrig;
		
		double counter = 0;
		for(int i=0;i<iters;i++){
			map<string, vector<int> > randomizedGroup = getRandomizedGroups(groupSampleMap);
			double ssWithinRand = calcSSWithin(randomizedGroup);
			if(ssWithinRand < ssWithinOrig){	counter++;	}
		}
		
		double pValue = (double)counter / (double) iters;
		string pString = "";
		if(pValue < 1/(double)iters){	pString = '<' + toString(1/(double)iters);	}
		else						{	pString = toString(pValue);					}
		
		
		//print anova table
		it = groupSampleMap.begin();
		AMOVAFile << it->first;
		m->mothurOut(it->first);
		it++;
		for(it;it!=groupSampleMap.end();it++){
			AMOVAFile << '-' << it->first;
			m->mothurOut('-' + it->first);
		}
		
		AMOVAFile << "\tAmong\tWithin\tTotal" << endl;
		m->mothurOut("\tAmong\tWithin\tTotal\n");
		
		AMOVAFile << "SS\t" << ssAmongOrig << '\t' << ssWithinOrig << '\t' << ssTotalOrig << endl;
		m->mothurOut("SS\t" + toString(ssAmongOrig) + '\t' + toString(ssWithinOrig) + '\t' + toString(ssTotalOrig) + '\n');
		
		int dfAmong = numGroups - 1;				double MSAmong = ssAmongOrig / (double) dfAmong;
		int dfWithin = totalNumSamples - numGroups;	double MSWithin = ssWithinOrig / (double) dfWithin;
		int dfTotal = totalNumSamples - 1;			double Fs = MSAmong / MSWithin;
		
		AMOVAFile << "df\t" << dfAmong << '\t' << dfWithin << '\t' << dfTotal << endl;
		m->mothurOut("df\t" + toString(dfAmong) + '\t' + toString(dfWithin) + '\t' + toString(dfTotal) + '\n');

		AMOVAFile << "MS\t" << MSAmong << '\t' << MSWithin << endl << endl;
		m->mothurOut("MS\t" + toString(MSAmong) + '\t' + toString(MSWithin) + "\n\n");

		AMOVAFile << "Fs:\t" << Fs << endl;
		m->mothurOut("Fs:\t" + toString(Fs) + '\n');
		
		AMOVAFile << "p-value: " << pString;
		m->mothurOut("p-value: " + pString);

		if(pValue < alpha){
			AMOVAFile << "*";
			m->mothurOut("*");
		}
		AMOVAFile << endl << endl;
		m->mothurOutEndLine();m->mothurOutEndLine();

		return pValue;
	}
	catch(exception& e) {
		m->errorOut(e, "AmovaCommand", "runAMOVA");
		exit(1);
	}
}
开发者ID:azerxu,项目名称:mothur,代码行数:74,代码来源:amovacommand.cpp

示例11: GetGame

//! 保存个人房屋内的物品信息
bool    CRsDupRgn::SaveDupRgnObj(const CGUID& ownerID, map<CGUID,CDBRgnGoods*>& goodsGroup, _ConnectionPtr& cn)
{

	if(cn == NULL)
	{
		AddLogText(CStringReading::LoadString(IDS_DBS_RSDUPRGN,STR_DBS_DUPRGN_CNPTRNULL));
		return false;
	}

	_RecordsetPtr rs;
	// 比物品个数多分配2048字节
	char *sql = new char[1024 * (goodsGroup.size()+2)];
	
	string iniName   = "phrgnobj";
	string tableName = "CSL_DUPRGN_GOODS";
	try
	{
		TESTHR(CreateRs(rs));

		char szGUID[128];
		ownerID.tostring(szGUID);

		sprintf(sql, "DELETE FROM CSL_DUPRGN_GOODS WHERE DupRgnGUID='%s'", szGUID);
		// 先删除该个人房屋的成员
		if(!ExecuteCn(sql, cn))
		{
			PrintErr(CStringReading::LoadString(IDS_DBS_RSDUPRGN,STR_DBS_DUPRGN_DELRGNOBJFAIL));
			return false;
		}

		// 清空sql语句
		memset(sql, 0, 1024 * (goodsGroup.size()+2));

		// 生成语句头
		strcpy(sql, "INSERT INTO CSL_DUPRGN_GOODS(");

		CDataEntityManager* pObjAttrDef = NULL;
		std::map<string, CDataEntityManager*>::iterator itr = GetGame()->GetDBEntityManager()->GetObjAttrDef().find(iniName);
		if(itr != GetGame()->GetDBEntityManager()->GetObjAttrDef().end())
			pObjAttrDef = itr->second;

		if(!pObjAttrDef) return false;

		//! 生成语句身
		CDataEntityManager::EntityPropertyMapItr attrItr = pObjAttrDef->GetEntityPropertyMap().begin();
		for (; attrItr != pObjAttrDef->GetEntityPropertyMap().end(); attrItr++)
		{
			if(attrItr->second->GetDBTableName() == tableName)
			{
				CWrapDataObject* wdo = attrItr->second->GetDataObject(0);
				if(wdo)
				{
					// 添加属性字段名
					strcat(sql, attrItr->second->GetEPName().c_str());
					strcat(sql, ",");
				}
			}
		}

		long sqlLen = strlen(sql);
		sql[sqlLen-1] = '\0';
		strcat(sql, ") select ");

		map<CGUID,CDBRgnGoods*>::iterator goodsItr = goodsGroup.begin();
		for(; goodsItr != goodsGroup.end(); goodsItr++)
		{	
			//! 生成语句身
			attrItr = pObjAttrDef->GetEntityPropertyMap().begin();
			for (; attrItr != pObjAttrDef->GetEntityPropertyMap().end(); attrItr++)
			{
				if(attrItr->second)
				{
					if(attrItr->second->GetDBTableName() == tableName)
					{
						// 添加属性字段值
						CEntityProperty* ep = (goodsItr->second)->GetDataEntityManager().GetEntityProperty(attrItr->second->GetEPName());
						if(ep)
						{
							if(ep->GetDBTableName() == tableName)
							{
								switch(ep->GetDataType())
								{
								case DATA_OBJECT_TIME:
									{
										char szTimeValue[2048];
										DWORD timeValue[6] = {0};
										ep->GetBufAttr(0, (void*)&timeValue[0], sizeof(DWORD)*6);
										sprintf(szTimeValue, "%d-%d-%d %d:%d:%d", timeValue[0], timeValue[1], timeValue[2],
											timeValue[3], timeValue[4], timeValue[5]);
										//rs->PutCollect((*epItr).c_str(), szTimeValue);
										strcat(sql, "'");
										strcat(sql, szTimeValue);
										strcat(sql, "',");
									}
									break;
								case  DATA_OBJECT_STRING:
									{
										//rs->PutCollect((*epItr).c_str(), );
										strcat(sql, "'");
//.........这里部分代码省略.........
开发者ID:xiongshaogang,项目名称:mmo-resourse,代码行数:101,代码来源:RsDupRgn.cpp

示例12: Operate

bool Expression::Operate(const map<string, float>& mapOperandValue, float& Result)
{
	if(operands->GetKeyCount() > mapOperandValue.size() + constant_float.size())
		return false;
	stack<float> stackOperand;//操作数
	Result = 0;
	string variable;
	map<string, float>::const_iterator iter;
	vector<float> operand_values;
	for(unsigned int index = 0; index < m_vecPostfixExp.size(); index++)
	{
		if(m_vecPostfixExp[index].enum_item_type == OPERAND)
		{
			variable = operands->GetKey(*((uint32_t*)m_vecPostfixExp[index].item));
			iter = mapOperandValue.find(variable);
			if(iter == mapOperandValue.end())
			{
				iter = constant_float.find(variable);
				if(iter == constant_float.end())
				{
#ifdef DEBUG
					cout<<"[EXPRESSION ERROR] find operand's value failed [operand = "<<this<<","<<constant_float.size()<<","<<constant_int.size()<<", "<<variable<<"]"<<endl;
#endif
					return false;
				}
			}
#ifdef DEBUG
			cout<<"push operand:"<<iter->second<<endl;
#endif
			stackOperand.push(iter->second);
		}
		else
		{
			// 从栈中弹出需要的操作数个数
			OperatorType Oper = *(OperatorType*)(m_vecPostfixExp[index].item);
			map<OperatorType, OperatorParameter>::iterator iterOper = mapOperatorPriority.find(Oper);
			if(iterOper == mapOperatorPriority.end())
			{
#ifdef DEBUG
				cout<<"[EXPRESSION ERROR] "<<Oper<<": unknown operator."<<endl;
#endif
				return false;
			}
#ifdef DEBUG
			cout<<"Oper : "<<GetOperatorName(Oper)<<" need "<<iterOper->second.operands<<" operands."<<endl;
#endif

			// 栈中的操作数小于操作符所需的操作数
			if(stackOperand.size() < iterOper->second.operands)
			{
#ifdef DEBUG
				cout<<"[EXPRESSION ERROR] operator needs more operands than "<<stackOperand.size()<<endl;
#endif
				return false;
			}
			// 依次弹出所需的操作数,先弹出的操作数在最右边
			// 为了简化,本解析器暂时不处理三个及三个以上的操作数
			operand_values.clear();
#ifdef DEBUG
			cout<<"operate : "<<Oper<<" on:";
#endif
			while(stackOperand.size() > 0 && operand_values.size() < iterOper->second.operands)
			{
#ifdef DEBUG
				cout<<stackOperand.top()<<",";
#endif
				operand_values.push_back(stackOperand.top());
				stackOperand.pop();
			}
			float result = DoOperating(Oper, operand_values);
#ifdef DEBUG
			cout<<"result = "<<result<<endl;
#endif
			stackOperand.push(result);
		}
	}

	// 正确运算结果是最后留下在栈中的那个值
	if(stackOperand.size() != 1)
	{
#ifdef DEBUG
		cout<<"[EXPRESSION ERROR] En? It looks like something wrong happened."<<endl;
#endif
		return false;
	}

	Result = stackOperand.top();

	return true;
}
开发者ID:xingwudao,项目名称:kaijiang_base_tools,代码行数:90,代码来源:expression.cpp

示例13: InitializePriority

/////////////////////////////////////////////////
// 说明:初始化操作符优先级
void InitializePriority()
{
	if(mapOperatorPriority.size() > 0)
	  return;
	OperatorParameter operator_parameter;
	operator_parameter.priority = 5;
	operator_parameter.operands = 0;
	operator_parameter.type = 8;
	mapOperatorPriority[LEFT_BRACKET] = operator_parameter;
	//mapOperatorPriority[LEFT_BRACKET] = pair<uint32_t, uint32_t>(5, 0);
	mapOperatorName["("] = LEFT_BRACKET;
	mapOperatorPriority[RIGHT_BRACKET] = operator_parameter;
	mapOperatorName[")"] = RIGHT_BRACKET;
	// 负号不保存名字
	operator_parameter.priority = 6;
	operator_parameter.operands = 1;
	operator_parameter.type = 1;
	mapOperatorPriority[NEGATIVE] = operator_parameter;
	//mapOperatorPriority[NEGATIVE] = pair<uint32_t, uint32_t>(6,1);

	// 优先级相同的在运算时按照出现的先后顺序计算
	mapOperatorName["*"] = MUTIPLY;
	operator_parameter.priority = 7;
	operator_parameter.operands = 2;
	operator_parameter.type = 1;
	mapOperatorPriority[MUTIPLY] = operator_parameter;
	//mapOperatorPriority[MUTIPLY] = pair<uint32_t, uint32_t>(7, 2);
	mapOperatorName["/"] = DEVIDE;
	mapOperatorPriority[DEVIDE] = operator_parameter;
	//mapOperatorPriority[DEVIDE] = pair<uint32_t, uint32_t>(7, 2);
	mapOperatorName["%"] = MODE;
	mapOperatorPriority[MODE] = operator_parameter;
	//mapOperatorPriority[MODE] = pair<uint32_t, uint32_t>(7, 2);

	mapOperatorName["+"] = PLUS;
	operator_parameter.priority = 8;
	operator_parameter.operands = 2;
	operator_parameter.type = 1;
	mapOperatorPriority[PLUS] = operator_parameter;
	//mapOperatorPriority[PLUS] = pair<uint32_t, uint32_t>(8, 2);
	mapOperatorName["-"] = MINUS;
	mapOperatorPriority[MINUS] = operator_parameter;
	//mapOperatorPriority[MINUS] = pair<uint32_t, uint32_t>(8, 2);

	mapOperatorName["<"] = LESS_THAN;
	operator_parameter.priority = 9;
	operator_parameter.operands = 2;
	operator_parameter.type = 4;
	mapOperatorPriority[LESS_THAN] = operator_parameter;
	//mapOperatorPriority[LESS_THAN] = pair<uint32_t, uint32_t>(9, 2);
	mapOperatorName[">"] = MORE_THAN;
	mapOperatorPriority[MORE_THAN] = operator_parameter;
	//mapOperatorPriority[MORE_THAN] = pair<uint32_t, uint32_t>(9, 2);
	mapOperatorName["<="] = LESS_EQUAL;
	mapOperatorPriority[LESS_EQUAL] = operator_parameter;
	//mapOperatorPriority[LESS_EQUAL] = pair<uint32_t, uint32_t>(9, 2);
	mapOperatorName[">="] = MORE_EQUAL;
	mapOperatorPriority[MORE_EQUAL] = operator_parameter;
	//mapOperatorPriority[MORE_EQUAL] = pair<uint32_t, uint32_t>(9, 2);

	mapOperatorName["=="] = EQUAL_TO;
	operator_parameter.priority = 10;
	operator_parameter.operands = 2;
	operator_parameter.type = 4;
	mapOperatorPriority[EQUAL_TO] = operator_parameter;
	//mapOperatorPriority[EQUAL_TO] = pair<uint32_t, uint32_t>(10, 2);
	mapOperatorName["!="] = NOT_EQUAL;
	mapOperatorPriority[NOT_EQUAL] = operator_parameter;
	//mapOperatorPriority[NOT_EQUAL] = pair<uint32_t, uint32_t>(10, 2);

	mapOperatorName["^"] = XOR;
	operator_parameter.priority = 11;
	operator_parameter.operands = 2;
	operator_parameter.type = 2;
	mapOperatorPriority[XOR] = operator_parameter;
	//mapOperatorPriority[XOR] = pair<uint32_t, uint32_t>(11, 2);
	mapOperatorName["&&"] = AND;
	operator_parameter.priority = 12;
	mapOperatorPriority[AND] = operator_parameter;
	//mapOperatorPriority[AND] = pair<uint32_t, uint32_t>(12, 2);
	mapOperatorName["||"] = OR;
	operator_parameter.priority = 13;
	mapOperatorPriority[OR] = operator_parameter;
	//mapOperatorPriority[OR] = pair<uint32_t, uint32_t>(13, 2);
}
开发者ID:xingwudao,项目名称:kaijiang_base_tools,代码行数:87,代码来源:expression.cpp

示例14: miningTemplate_02

void miningTemplate_02(RuleNode* initRule, vector<Label*> &previousLabels) 
{
	int i,j,k;
	map<string,int>::iterator it;
	map<string,int>::iterator it1;
	map<string,int> possibleViews;
	map<string,int> allNextEvents;
	for(i=0;i<previousLabels.size();i++)
	{
		if(previousLabels[i]->eventNum < traceSet[previousLabels[i]->traceNum].size()-2)
		{
			//stored nextViewName as hashkey
			string nextViewName=traceSet[previousLabels[i]->traceNum][previousLabels[i]->eventNum+1]->name;
			
			if(possibleViews.find(nextViewName)!=possibleViews.end())
			{
				possibleViews[nextViewName]++;
			}
			else
			{
				possibleViews[nextViewName]=1;
			}
			cout<<possibleViews[nextViewName]<<"view"<<endl;
		}
			// ABABCDE
			//						A			C			E
			//(0,0)(0,1)			1			1			1
			//(0,2)(0,3)			0			1			1

			//create a table and fill zero into table
		vector <vector<int>> table;
		table.resize(possibleViews.size());
		for(i=0;i<table.size();i++)
		{ 
			table[i].resize(allStateEvents.size());
			for(j=0;j<allStateEvents.size();j++)
			{
				table[i][j]=0;
			}
		}
 
		for(it=possibleViews.begin();it!=possibleViews.end();it++)			
		{
			for(j=0;j<allStateEvents.size();j++)
			{
				for(k=0;k<traceSet[j].size();k++)
				{
					if(traceSet[j][k]->name==it1->first)
					{
						table[j][k]=1;
					}
				}
			}
		}

		//calculate the number of StateEvent
		int count=0;
		for(i=0;i<possibleViews.size();i++)	
		{
	
			for(j=0;j<allStateEvents.size();j++)
			{
				if(table[i][j]=1)
				{
					count++;
				}
			}
		}
		//calculate confidence and recursive
		map<string,int>::iterator it;
		for(it=allNextEvents.begin();it!=allNextEvents.end();++it)
		{
			double a=it->second;
			double b=previousLabels.size();
			if( a/b >= confidenceThreshold)
			{
				//seperate the combinedName
				for(i=0;i < it->first.size();i++)
				{
					if(it->first[i]=='+')
					{
						break;
					}
				}
				string childViewEventName=it->first.substr(0,i);
				string childStateEventName=it->first.substr(i+1,it->first.size()-i-1);
				//update labels
				vector<Label*> nextLabels;
				for(i=0;i<previousLabels.size();i++)
				{
					if(previousLabels[i]->eventNum < traceSet[previousLabels[i]->traceNum].size()-2)
					{
						if(traceSet[previousLabels[i]->traceNum][previousLabels[i]->eventNum+1]->name==childViewEventName && 
						traceSet[previousLabels[i]->traceNum][previousLabels[i]->eventNum+2]->name==childStateEventName)
						{
							Label* newLabel=new Label(previousLabels[i]->traceNum,previousLabels[i]->eventNum+2);
							nextLabels.push_back(newLabel);
						}					
					}
				}
//.........这里部分代码省略.........
开发者ID:hhhgtr00055,项目名称:SpecTemplateMiner,代码行数:101,代码来源:miner.cpp

示例15: on_accept

/**
 * This function will be called by libevent when there is a connection
 * ready to be accepted.
 */
static void on_accept(evutil_socket_t fd, short ev, void *arg)
{
	int client_fd;
	struct sockaddr_in client_addr;
	socklen_t client_len = (socklen_t)sizeof(client_addr);
	static int maxfd = 80000;
	
	client_fd = accept(fd, (struct sockaddr *)&client_addr, &client_len);
	if (client_fd == -1)
    {
        fprintf(stderr, "accept failed. errno:%d, info:%s\n", 
            EVUTIL_SOCKET_ERROR(), get_error_string(EVUTIL_SOCKET_ERROR()));
		return;
	}

	if(client_fd > maxfd + 1000)
    {
		maxfd = client_fd;
		printf("maxfd %d\n", maxfd );
	}

    if (g_tcp_send_buf_len >= 0)
    {
        setsockopt(client_fd, SOL_SOCKET, SO_SNDBUF, (const char*)&g_tcp_send_buf_len, sizeof(int));
    }
	
	if (g_no_delay)
	{
		int flag;
		setsockopt(client_fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag));
	}
	
//	setsockopt(client_fd, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, (char *)&fd, sizeof(fd));
	
	/* Set the client socket to non-blocking mode. */
	if (evutil_make_socket_nonblocking(client_fd) < 0)
    {
		fprintf(stderr, "failed to set client socket non-blocking.\n");
    }

    server_conn *nlc = new server_conn(client_fd);
   	event_set(nlc->get_ev_read(), client_fd, EV_READ, on_read, nlc);
  	event_set(nlc->get_ev_write(), client_fd, EV_WRITE | EV_PERSIST, on_write, nlc);
    nlc->set_max_send_len(g_send_buf_len);
    if (!g_same)
    {
        nlc->set_mask((unsigned int)genrand64_int64());
    }
    nlc->set_block(g_block);
    nlc->set_check(g_check);
	nlc->set_alter(g_alter);
    nlc->set_debug_level(g_verbose);

 	printf("accepted connection(%d) from %s:%d.\n", client_fd, inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));

    g_conns.insert(pair<int, server_conn *>(client_fd, nlc));
    printf("current connected sockets number:%u\n", (unsigned int)g_conns.size());

    if(event_add(nlc->get_ev_read(), NULL) != 0)
    {
        nlc->set_error_no(NL_CONN_ERROR_EV_READ);
        close_client(client_fd);
        fprintf(stderr, "event_add failed(%d) from %s:%d.\n", client_fd, inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
 	}
}
开发者ID:wdj729115299,项目名称:conn_test,代码行数:69,代码来源:main.cpp


注:本文中的map::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。