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


C++ vector::at方法代码示例

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


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

示例1: StaticBoundList

KListRef Win32UserWindow::SelectFile(bool saveDialog, bool multiple, std::string& title,
	std::string& path, std::string& defaultName, std::vector<std::string>& types,
	std::string& typesDescription)
{
	std::wstring filter;
	std::wstring typesDescriptionW = ::UTF8ToWide(typesDescription);
	if (types.size() > 0)
	{
		//"All\0*.*\0Test\0*.TXT\0";
		if (typesDescription.size() == 0)
		{
			// Reasonable default?
			typesDescriptionW = L"Selected Files";
		}
		filter.append(typesDescriptionW);
		filter.push_back(L'\0');
		
		for (int i = 0; i < types.size(); i++)
		{
			std::string type = types.at(i);
			std::wstring typeW = ::UTF8ToWide(type);
			//multiple filters: "*.TXT;*.DOC;*.BAK"
			size_t found = type.find("*.");
			if (found != 0)
			{
				filter.append(L"*.");
			}
			filter.append(typeW);
			filter.append(L";");
		}
		filter.push_back(L'\0');
	}

	OPENFILENAME ofn;

	std::wstring pathW = ::UTF8ToWide(path);
	ZeroMemory(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = this->windowHandle;

	// Windows may not null-terminate the string it puts here, so we zero it.
	wchar_t filenameW[MAX_FILE_DIALOG_STRING];
	ZeroMemory(&filenameW, MAX_FILE_DIALOG_STRING * sizeof(wchar_t));
	wcscpy(filenameW, ::UTF8ToWide(defaultName).c_str());
	ofn.lpstrFile = filenameW;

	ofn.nMaxFile = MAX_FILE_DIALOG_STRING;
	ofn.lpstrFilter = (LPWSTR) (filter.size() == 0 ? 0 : filter.c_str());
	ofn.nFilterIndex = 1;
	ofn.lpstrFileTitle = 0;
	ofn.nMaxFileTitle = 0;
	ofn.lpstrInitialDir = (LPWSTR) (pathW.length() == 0 ? 0 : pathW.c_str());
	ofn.Flags = OFN_EXPLORER;

	std::wstring titleW;
	if (!title.empty())
	{
		titleW = ::UTF8ToWide(title);
		ofn.lpstrTitle = titleW.c_str();
	}

	if (!saveDialog)
	{
		ofn.Flags |= OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
	}

	if (multiple)
	{
		ofn.Flags |= OFN_ALLOWMULTISELECT;
	}

	
	BOOL result;
	if (saveDialog)
	{
		result = ::GetSaveFileName(&ofn);
	}
	else
	{
		result = ::GetOpenFileName(&ofn);
	}

	// A zero-return value here indicates either an error or that the user
	// cancelled the action (CommDlgExtendedError returns 0). We should
	// return a helpful exception if it's an error.
	if (!result)
	{
		DWORD code = CommDlgExtendedError();
		if (code == 0)
			return new StaticBoundList();

		throw ValueException::FromFormat(
			"File dialog action failed with error code: %i", code);
	}

	// From:  http://msdn.microsoft.com/en-us/library/ms646839(VS.85).aspx
	// If multiple files have been selected there will be two '\0' characters
	// at the end of this array of characters, so if we enabled multiple file
	// selected, just check for that second '\0'.
	KListRef results = new StaticBoundList();
//.........这里部分代码省略.........
开发者ID:ksmythe,项目名称:titanium_desktop,代码行数:101,代码来源:win32_user_window.cpp

示例2: getArgument

Argument Sphere_SDFOP::getArgument(unsigned int index)
{
    return args.at(index);
}
开发者ID:docwhite,项目名称:Romanesco,代码行数:4,代码来源:Sphere_SDFOP.cpp

示例3: getVariable

long double* getVariable(long double variablePos) {
    return &variableMap[vecVariablesNames.at(variablePos)];
}
开发者ID:MCRewind,项目名称:Calculator,代码行数:3,代码来源:main.cpp

示例4: completion_try_print

static int completion_try_print(int cols,
                                const wchar_t *prefix,
                                int is_quoted,
                                std::vector<comp_t *> &lst)
{
    /*
      The calculated preferred width of each column
    */
    int pref_width[PAGER_MAX_COLS];
    /*
      The calculated minimum width of each column
    */
    int min_width[PAGER_MAX_COLS];
    /*
      If the list can be printed with this width, width will contain the width of each column
    */
    int *width=pref_width;
    /*
      Set to one if the list should be printed at this width
    */
    int print=0;

    long i, j;

    int rows = (int)((lst.size()-1)/cols+1);

    int pref_tot_width=0;
    int min_tot_width = 0;
    int res=PAGER_RETRY;
    /*
      Skip completions on tiny terminals
    */

    if (termsize.ws_col < PAGER_MIN_WIDTH)
        return PAGER_DONE;

    memset(pref_width, 0, sizeof(pref_width));
    memset(min_width, 0, sizeof(min_width));

    /* Calculate how wide the list would be */
    for (j = 0; j < cols; j++)
    {
        for (i = 0; i<rows; i++)
        {
            int pref,min;
            comp_t *c;
            if (lst.size() <= j*rows + i)
                continue;

            c = lst.at(j*rows + i);
            pref = c->pref_width;
            min = c->min_width;

            if (j != cols-1)
            {
                pref += 2;
                min += 2;
            }
            min_width[j] = maxi(min_width[j],
                                min);
            pref_width[j] = maxi(pref_width[j],
                                 pref);
        }
        min_tot_width += min_width[j];
        pref_tot_width += pref_width[j];
    }
    /*
      Force fit if one column
    */
    if (cols == 1)
    {
        if (pref_tot_width > termsize.ws_col)
        {
            pref_width[0] = termsize.ws_col;
        }
        width = pref_width;
        print=1;
    }
    else if (pref_tot_width <= termsize.ws_col)
    {
        /* Terminal is wide enough. Print the list! */
        width = pref_width;
        print=1;
    }
    else
    {
        long next_rows = (lst.size()-1)/(cols-1)+1;
        /*    fwprintf( stderr,
          L"cols %d, min_tot %d, term %d, rows=%d, nextrows %d, termrows %d, diff %d\n",
          cols,
          min_tot_width, termsize.ws_col,
          rows, next_rows, termsize.ws_row,
          pref_tot_width-termsize.ws_col );
        */
        if (min_tot_width < termsize.ws_col &&
                (((rows < termsize.ws_row) && (next_rows >= termsize.ws_row)) ||
                 (pref_tot_width-termsize.ws_col< 4 && cols < 3)))
        {
            /*
              Terminal almost wide enough, or squeezing makes the
//.........这里部分代码省略.........
开发者ID:DarkStarSword,项目名称:fish-shell,代码行数:101,代码来源:fish_pager.cpp

示例5: nPoints

std::vector<gmtl::Point3f> nPoints(std::vector<gmtl::Point3f> verts, char shape)
{
	std::vector<gmtl::Point3f> _normals;
	switch (shape)
	{

	case 's':
		for (GLuint i = 0; i < verts.size();)
		{
			gmtl::Point3f oldP = verts.at(i);
			//magnitude given by a^2 + b^2 + c^2
			GLfloat oldX = oldP[0];
			GLfloat oldY = oldP[1];
			GLfloat oldZ = oldP[2];
			GLfloat magnitude = sqrt(oldX * oldX + oldY * oldY + oldZ * oldZ);
			//normalized value given by vert/magnitude
			GLfloat newX = oldX / magnitude;
			GLfloat newY = oldY / magnitude;
			GLfloat newZ = oldZ / magnitude;

			gmtl::Point3f newP(newX, newY, newZ);
			_normals.push_back(newP);
			i++;
		}
		break;
	case 'c':
		for (GLuint i = 0; i < verts.size();)
		{
			gmtl::Point3f oldP = verts.at(i);
			//magnitude given by a^2 + b^2 + c^2
			GLfloat oldX = oldP[0];
			GLfloat oldY = oldP[1];
			GLfloat oldZ = oldP[2];
			GLfloat magnitude = sqrt(oldX * oldX + oldY * oldY + oldZ * oldZ);
			//normalized value given by vert/magnitude
			GLfloat newX = oldX / magnitude;
			GLfloat newY = oldY / magnitude;
			GLfloat newZ = oldZ / magnitude;

			gmtl::Point3f newP(newX, newY, newZ);
			_normals.push_back(newP);
			i++;
		}
		break;
	case 'a':
		for (GLuint i = 0; i < verts.size();)
		{
			gmtl::Point3f oldP = verts.at(i);
			//magnitude given by a^2 + b^2 + c^2
			GLfloat oldX = oldP[0];
			GLfloat oldY = oldP[1];
			GLfloat oldZ = oldP[2];
			GLfloat magnitude = sqrt(oldX * oldX + oldY * oldY + oldZ * oldZ);
			//normalized value given by vert/magnitude
			GLfloat newX = oldX / magnitude;
			GLfloat newY = oldY / magnitude;
			GLfloat newZ = oldZ / magnitude;

			gmtl::Point3f newP(newX, newY, newZ);
			_normals.push_back(newP);
			i++;
		}
		break;
	case 'b':
		for (GLuint i = 0; i < verts.size();)
		{
			gmtl::Point3f oldP = verts.at(i);
			//magnitude given by a^2 + b^2 + c^2
			GLfloat oldX = oldP[0];
			GLfloat oldY = oldP[1];
			GLfloat oldZ = oldP[2];
			GLfloat magnitude = sqrt(oldX * oldX + oldY * oldY + oldZ * oldZ);
			//normalized value given by vert/magnitude
			GLfloat newX = oldX / magnitude;
			GLfloat newY = oldY / magnitude;
			GLfloat newZ = oldZ / magnitude;

			gmtl::Point3f newP(newX, newY, newZ);
			_normals.push_back(newP);
			i++;
		}
		break;
	}


	return _normals;
}
开发者ID:chuwilliamson,项目名称:CMPS-415,代码行数:87,代码来源:Geometry.cpp

示例6: evaluate

inline void Maxscoreqi::evaluate(lptrArray& lps, QpResult* res, const float& threshold, const int topK, const int& num_of_essential_lists, int& smallest_did, std::vector <float>& lists_maxscore, const float& current_prefix_sum_max_score, bool& check_for_new_essential_list, const int& threshold_unknown, const int& comparison, int& next_smallest_did) {
    bool failure = false;
    float final_score = 0.0f;
    next_smallest_did = CONSTS::MAXD + 1;

    string terms[2];
    float scores[2];
    int freq[2];

    scores[0] = 0;
    scores[1] = 0;
    freq[0] = 0;
    freq[1] = 0;

    float frequency = 0;
    float score = 0;

    // evaluate dids == to smallest_did in the essential lists
    //for (int i=num_of_essential_lists; i<lps.size(); i++) {         // In order version
    for (int i = lps.size()-1; i>=num_of_essential_lists; --i) {      // Reverse order version

        terms[i] = lps[i]->term;

        if (smallest_did == lps[i]->did) {
            //PROFILER(CONSTS::EVAL);
            //PROFILER(CONSTS::GETFREQ);
            //PROFILER(CONSTS::ESSENTIAL);
            const float frequency = lps[i]->getFreq();
            const float score = lps[i]->calcScore(frequency,pages[smallest_did]);
            scores[i] = score;
            freq[i] = frequency;
            final_score += score;
            lps[i]->did = lps[i]->nextGEQ( smallest_did + 1 );
            //PROFILER(CONSTS::NEXTGEQ);
        }

        // pick next smallest did
        if (lps[i]->did < next_smallest_did)
            next_smallest_did = lps[i]->did;
    }

    // early termination = prefix + final score of essential lists
    float early_termination = current_prefix_sum_max_score + final_score;

    // if early termination check is passed, evaluate smallest did in the non-essential set
    if (! (Fcompare(early_termination, threshold) <= comparison)) {
        // evaluate dids == to smallest_did in the non essential lists
        //for (int i = 0; i < num_of_essential_lists; ++i)	{       // In order version
        for (int i=num_of_essential_lists-1; i>=0; --i)	{           // Reverse order version

            terms[i] = lps[i]->term;

            // move pointers if needed
            if (lps[i]->did < smallest_did) {
                //PROFILER(CONSTS::NEXTGEQ1);
                lps[i]->did = lps[i]->nextGEQ(smallest_did);
                //PROFILER(CONSTS::NEXTGEQ);
            }

            // check if evaluation is needed
            if (smallest_did == lps[i]->did) {
                //PROFILER(CONSTS::EVAL);
                //PROFILER(CONSTS::GETFREQ);
                //PROFILER(CONSTS::NONESSENTIAL);
                const float frequency = lps[i]->getFreq();
                const float score = lps[i]->calcScore(frequency,pages[smallest_did]);
                scores[i] = score;
                freq[i] = frequency;
                final_score += score;
                early_termination -= (lists_maxscore.at(i) - score);
            } else
                early_termination -= lists_maxscore.at(i);

            // early termination
            if (Fcompare(early_termination, threshold) <= comparison) {
                failure = true;
                //PROFILER(CONSTS::EARLYTERMINATION2);
                break;
            }
        }

        // if not failure, heapify new result
        if ((!failure) && (Fcompare(final_score, threshold) >= threshold_unknown)) {
            //PROFILER(CONSTS::HEAPIFY);
            check_for_new_essential_list = true;
            int j;
            for (j = topK-2; (j >= 0) && (Fcompare(final_score, res[j].score)==1); j--)
                res[j+1]=res[j];
            // res[j+1].setR(smallest_did,final_score);
            res[j+1].setRQi(smallest_did,final_score,terms,scores,freq);
        }
    } else {  // togo
        //PROFILER(CONSTS::EARLYTERMINATION1);
    }
}
开发者ID:amallia,项目名称:GP_Pangolin,代码行数:95,代码来源:Maxscoreqi.cpp

示例7: operator

 int& operator()(size_t x, size_t y, size_t z) {
     return m_data.at(x + y * m_width + z * m_width * m_height);
 }
开发者ID:farzonl,项目名称:ComputerVisonClassProjects,代码行数:3,代码来源:StereoImage.hpp

示例8: GetAnimStateByIndex

  const CPASAnimState* GetAnimStateByIndex(s32 index) const {
    if (index < 0 || index >= x0_states.size())
      return nullptr;

    return &x0_states.at(index);
  }
开发者ID:AxioDL,项目名称:urde,代码行数:6,代码来源:CPASDatabase.hpp

示例9: SetStringArray

void XMLUtils::SetStringArray(TiXmlNode* pRootNode, const char *strTag, const std::vector<std::string>& arrayValue)
{
  for (unsigned int i = 0; i < arrayValue.size(); i++)
    SetString(pRootNode, strTag, arrayValue.at(i));
}
开发者ID:eduardoabinader,项目名称:xbmc,代码行数:5,代码来源:XMLUtils.cpp

示例10:

/***********************************************************************
 * Structors
 **********************************************************************/
dbsrx::dbsrx(ctor_args_t args) : rx_dboard_base(args){
    //warn user about incorrect DBID on USRP1, requires R193 populated
    if (this->get_iface()->get_special_props().soft_clock_divider and this->get_rx_id() == 0x000D)
        UHD_LOGGER_WARNING("DBSRX") << boost::format(
                "DBSRX: incorrect dbid\n"
                "Expected dbid 0x0002 and R193\n"
                "found dbid == %d\n"
                "Please see the daughterboard app notes"
                ) % this->get_rx_id().to_pp_string();

    //warn user about incorrect DBID on non-USRP1, requires R194 populated
    if (not this->get_iface()->get_special_props().soft_clock_divider and this->get_rx_id() == 0x0002)
        UHD_LOGGER_WARNING("DBSRX") << boost::format(
                "DBSRX: incorrect dbid\n"
                "Expected dbid 0x000D and R194\n"
                "found dbid == %d\n"
                "Please see the daughterboard app notes"
                ) % this->get_rx_id().to_pp_string();

    //send initial register settings
    this->send_reg(0x0, 0x5);

    //set defaults for LO, gains, and filter bandwidth
    double codec_rate = this->get_iface()->get_codec_rate(dboard_iface::UNIT_RX);
    _bandwidth = 0.8*codec_rate/2.0; // default to anti-alias at different codec_rate

    ////////////////////////////////////////////////////////////////////
    // Register properties
    ////////////////////////////////////////////////////////////////////
    this->get_rx_subtree()->create<std::string>("name")
        .set("DBSRX");
    this->get_rx_subtree()->create<sensor_value_t>("sensors/lo_locked")
        .set_publisher(boost::bind(&dbsrx::get_locked, this));
    for(const std::string &name:  dbsrx_gain_ranges.keys()){
        this->get_rx_subtree()->create<double>("gains/"+name+"/value")
            .set_coercer(boost::bind(&dbsrx::set_gain, this, _1, name))
            .set(dbsrx_gain_ranges[name].start());
        this->get_rx_subtree()->create<meta_range_t>("gains/"+name+"/range")
            .set(dbsrx_gain_ranges[name]);
    }
    this->get_rx_subtree()->create<double>("freq/value")
        .set_coercer(boost::bind(&dbsrx::set_lo_freq, this, _1));
    this->get_rx_subtree()->create<meta_range_t>("freq/range")
        .set(dbsrx_freq_range);
    this->get_rx_subtree()->create<std::string>("antenna/value")
        .set(dbsrx_antennas.at(0));
    this->get_rx_subtree()->create<std::vector<std::string> >("antenna/options")
        .set(dbsrx_antennas);
    this->get_rx_subtree()->create<std::string>("connection")
        .set("IQ");
    this->get_rx_subtree()->create<bool>("enabled")
        .set(true); //always enabled
    this->get_rx_subtree()->create<bool>("use_lo_offset")
        .set(false);
    this->get_rx_subtree()->create<double>("bandwidth/value")
        .set_coercer(boost::bind(&dbsrx::set_bandwidth, this, _1));
    this->get_rx_subtree()->create<meta_range_t>("bandwidth/range")
        .set(dbsrx_bandwidth_range);

    //enable only the clocks we need
    this->get_iface()->set_clock_enabled(dboard_iface::UNIT_RX, true);

    //set the gpio directions and atr controls (identically)
    this->get_iface()->set_pin_ctrl(dboard_iface::UNIT_RX, 0x0); // All unused in atr
    if (this->get_iface()->get_special_props().soft_clock_divider){
        this->get_iface()->set_gpio_ddr(dboard_iface::UNIT_RX, 0x1); // GPIO0 is clock when on USRP1
    }
    else{
        this->get_iface()->set_gpio_ddr(dboard_iface::UNIT_RX, 0x0); // All Inputs
    }

    //now its safe to set inital freq and bw
    this->get_rx_subtree()->access<double>("freq/value")
        .set(dbsrx_freq_range.start());
    this->get_rx_subtree()->access<double>("bandwidth/value")
        .set(2.0*_bandwidth); //_bandwidth in lowpass, convert to complex bandpass
}
开发者ID:EttusResearch,项目名称:uhd,代码行数:80,代码来源:db_dbsrx.cpp

示例11: main

int main(int argc, char* argv[])
{
    char* infile = argv[1];

    if (argc < 2)
    {
        std::cerr << "Usage:" << argv[0] << " INPUT" << std::endl;
        return 1;
    }

    FileBuffer data(infile);
    NCFile<FileBuffer> file(data);

    std::vector<Dimension> const dims  = file.dimensions();
    std::vector<Variable>  const vars  = file.variables();
    Attributes const attrs = file.attributes();
    size_t i;

    std::cout << "netcdf " << stripname(infile) << " {" << std::endl;

    std::cout << "dimensions:" << std::endl;
    for (i = 0; i < dims.size(); ++i)
    {
        Dimension d = dims.at(i);
        std::cout << "\t" << d.name << " = " << d.size
                  << " ;" << std::endl;
    }
    std::cout << std::endl;

    std::cout << "variables:" << std::endl;
    for (i = 0; i < vars.size(); ++i)
    {
        Variable v = vars.at(i);
        std::cout << "\t" << tname(v.type()) << " " << v.name()
                  << "(" << toString(v.dimensionNames())
                  << ") ;" << std::endl;

        Attributes const attrs = v.attributes();
        for (size_t j = 0; j < attrs.size(); ++j)
        {
            Attribute a = attrs.at(j);
            std::cout << "\t\t" << v.name() << ":" << attrs.keyAt(j) << " = "
                      << formatString(a.valuesAsString())
                      << " ;" << std::endl;
        }
    }
    std::cout << std::endl;

    std::cout << "// global attributes:" << std::endl;
    for (i = 0; i < attrs.size(); ++i)
    {
        Attribute a = attrs.at(i);
        std::cout << "\t\t:" << attrs.keyAt(i) << " = "
                  << formatString(a.valuesAsString())
                  << " ;" << std::endl;
    }
    std::cout << std::endl;

    std::cout << "data:" << std::endl;
    for (i = 0; i < vars.size(); ++i)
    {
        Variable v = vars.at(i);
        std::cout << std::endl << " " << v.name() << " =" << std::endl;
        std::cout << "  " << file.valueAsString(v, 0, 0, 0)
                  << ", " << file.valueAsString(v, 1, 0, 0)
                  << ", " << file.valueAsString(v, 2, 0, 0)
                  << ", " << file.valueAsString(v, 3, 0, 0)
                  << ", " << file.valueAsString(v, 4, 0, 0)
                  << ", ... ;"
                  << std::endl;
    }

    std::cout << "}" << std::endl;
}
开发者ID:lzs203511,项目名称:diamorse,代码行数:74,代码来源:ncdump.C

示例12: update

 void update(Cell const v)
 {
     _nrPairableFacets.at(v) = 0;
     for (size_t i = 0; i < _coI.count(v); ++i)
         --_nrPairableFacets.at(_coI(v, i));
 }
开发者ID:rachellevanger,项目名称:diamorse,代码行数:6,代码来源:VectorFieldGyulassy.C

示例13: Replayer

 explicit Replayer(std::vector<std::string> args)
 {
   const char* actor_name     = args.at(0).c_str();
   const char* trace_filename = args.size() > 1 ? args[1].c_str() : nullptr;
   simgrid::xbt::replay_runner(actor_name, trace_filename);
 }
开发者ID:simgrid,项目名称:simgrid,代码行数:6,代码来源:s4u-replay-comm.cpp

示例14: DumpToHexString

 std::string DumpToHexString(const std::vector<Platform::byte> &data)
 {
     return DumpToHexString(&data.at(0), data.size());
 }
开发者ID:ixc-software,项目名称:lucksi,代码行数:4,代码来源:IntToString.cpp

示例15: stat_report_global

  void stat_report_global(FILE* output) {
    assert(GLOBAL_STATS.initialized);
    stat_finish_thread();

    std::unique_lock<std::mutex> global_lock(GLOBAL_STATS_MUTEX);
    std::fprintf(output, "# Dort statistics\n");

    std::fprintf(output, "## Counters\n");
    for(uint32_t i = 0; i < _COUNTER_END; ++i) {
      std::fprintf(output, "- %-30s  %10" PRIu64 "\n", 
          STAT_COUNTER_DEFS.at(i).name,
          GLOBAL_STATS.counters.at(i));
    }

    std::fprintf(output, "## Integer distributions\n");
    for(uint32_t i = 0; i < _DISTRIB_INT_END; ++i) {
      const auto& distrib = GLOBAL_STATS.distrib_ints.at(i);
      std::fprintf(output, "- %-30s  ", STAT_DISTRIB_INT_DEFS.at(i).name);
      if(distrib.count == 0) {
        std::fprintf(output, "(no samples)\n");
        continue;
      }

      float average = float(distrib.sum) / float(distrib.count);
      float average_square = float(distrib.sum_squares) / float(distrib.count);
      float variance = abs(average_square - average * average);
      float stddev = sqrt(variance);
      std::fprintf(output, "avg %g, sd %g, min %" PRIi64 ", max %" PRIi64
          ", n %" PRIu64 "\n", average, stddev, distrib.min, distrib.max,
          distrib.count);
    }

    std::fprintf(output, "## Time distributions\n");
    for(uint32_t i = 0; i < _TIMER_END; ++i) {
      const auto& distrib = GLOBAL_STATS.distrib_times.at(i);
      std::fprintf(output, "- %-30s  ", STAT_DISTRIB_TIME_DEFS.at(i).name);
      if(distrib.sampled_count == 0) {
        std::fprintf(output, "(no samples)\n");
        continue;
      }

      float average_ns = float(distrib.sum_ns) 
        / float(distrib.sampled_count);
      float average_square_ns = float(distrib.sum_squares_ns) 
        / float(distrib.sampled_count);
      float average_overhead_ns = float(distrib.sum_overhead_ns) 
        / float(distrib.sampled_count);
      float estimate_total_ns = average_ns * float(distrib.total_count);
      float variance = abs(average_square_ns - average_ns * average_ns);
      float stddev_ns = sqrt(variance);
      std::fprintf(output, "avg %g ns, sd %g ns, n %" PRIu64 "/%" PRIu64 ",",
          average_ns, stddev_ns, distrib.sampled_count, distrib.total_count);

      if(abs(estimate_total_ns) < 20e3f) {
        std::fprintf(output, " total ~%3g ns", estimate_total_ns);
      } else if(abs(estimate_total_ns) < 20e6f) {
        std::fprintf(output, " total ~%3g us", estimate_total_ns * 1e-3f);
      } else if(abs(estimate_total_ns) < 20e9f) {
        std::fprintf(output, " total ~%3g ms", estimate_total_ns * 1e-6f);
      } else if(abs(estimate_total_ns) < 2000e12f) {
        std::fprintf(output, " total ~%3g s", estimate_total_ns * 1e-9f);
      } else {
        std::fprintf(output, " total ~%3g min", estimate_total_ns * 1e-9f / 60.f);
      }

      std::fprintf(output, "\n                                  ");
      std::fprintf(output, "min %" PRIi64 " ns, max %" PRIi64 " ns, avg ohead %g ns\n",
          distrib.min_ns, distrib.max_ns, average_overhead_ns);
    }
  }
开发者ID:honzasp,项目名称:dort,代码行数:70,代码来源:stats.cpp


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