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


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

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


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

示例1: on_event

	virtual BOOL on_event (HELEMENT he, HELEMENT target, BEHAVIOR_EVENTS type, UINT_PTR reason ) 
	{ 
		switch( type )
		{
		case POPUP_READY: 
			{
				element ePopup(target);
				if (!ePopup.is_valid() || ePopup.children_count())
					return true;
				if (sg_vFontNames.empty())
				{
					LOGFONT lf;
					lf.lfFaceName[0] = L'\0';
					lf.lfCharSet = DEFAULT_CHARSET/*ANSI_CHARSET*/;
                    
                    HDC hDC = ::GetDC(NULL);
                    EnumFontFamiliesEx(hDC, &lf, (FONTENUMPROC)xEnumFontsProc, NULL, 0);
					::ReleaseDC(NULL,hDC);
					sg_vFontNames.shrink_to_fit();
				}
				ePopup.set_style_attribute("max-height",L"200");
				auto itrEnd = sg_vFontNames.end();
				element eItem;
				for (auto itr = sg_vFontNames.begin(); itr != itrEnd; ++itr)
				{
					eItem = element::create("option");
					ePopup.append(eItem);
					eItem.set_text((*itr).c_str());
					eItem.set_style_attribute("font-family",(*itr).c_str());
				}
				return true;
			}
		}
		return false;
	}
开发者ID:qiuchengw,项目名称:qui,代码行数:35,代码来源:behavior_fontname.cpp

示例2: log

//-----------------------------------------------------------------------------
std::pair<std::int32_t, std::int32_t>
GraphBuilder::compute_dual_graph(const MPI_Comm mpi_comm,
                                 const boost::multi_array<std::int64_t, 2>& cell_vertices,
                                 const CellType& cell_type,
                                 const std::int64_t num_global_vertices,
                                 std::vector<std::vector<std::size_t>>& local_graph,
                                 std::set<std::int64_t>& ghost_vertices)
{
  log(PROGRESS, "Build mesh dual graph");

  // Compute local part of dual graph
  FacetCellMap facet_cell_map;
  std::int32_t num_local_edges = compute_local_dual_graph(mpi_comm, cell_vertices,
                                                          cell_type, local_graph,
                                                          facet_cell_map);

  // Compute nonlocal part
  std::int32_t num_nonlocal_edges
    = compute_nonlocal_dual_graph(mpi_comm, cell_vertices, cell_type,
                                  num_global_vertices, local_graph, facet_cell_map,
                                  ghost_vertices);

  // Shrink to fit
  local_graph.shrink_to_fit();

  return {num_local_edges, num_nonlocal_edges};
}
开发者ID:WeilinDeng,项目名称:dolfin,代码行数:28,代码来源:GraphBuilder.cpp

示例3: resolver

//##############################################################################
//##############################################################################
static std::vector<boost::asio::ip::address>
get_peer_addresses(std::vector<std::string> peers)
{
    range::Emitter log { get_peer_addressesLogModule };
    RANGE_LOG_FUNCTION();

    std::sort(peers.begin(), peers.end());
    std::unique(peers.begin(), peers.end());
    peers.shrink_to_fit();

    std::vector<boost::asio::ip::address> addrs;

    boost::asio::io_service io_service;

    for (std::string peer : peers) {
        boost::asio::ip::udp::resolver resolver(io_service);
        boost::asio::ip::udp::resolver::query query(peer, "");
       
        try { 
            for(auto it = resolver.resolve(query); it != decltype(it)(); ++it) {
                addrs.push_back(it->endpoint().address());
            }
        } catch (boost::system::system_error &e) {
            LOG(warning, "unable_to_resolve") << peer;
        }
    }

    std::sort(addrs.begin(), addrs.end());
    std::unique(addrs.begin(), addrs.end());
    addrs.shrink_to_fit();

    return addrs;
}
开发者ID:jbeverly,项目名称:rangexx,代码行数:35,代码来源:startup.cpp

示例4: considerOffers

void Peer::considerOffers(std::vector<std::pair<Peer*, std::vector<size_t>>>& offers)
{
	// Sanity check: We should only be getting offers for things we don't have
#ifndef NDEBUG
	for (auto& offerSet : offers) {
		for (size_t offer : offerSet.second)
			assert(!chunkList[offer]);
	}
#endif

	assert(consideredOffers.empty());

	auto popularity = getChunkPopularity();

	// Coalesce our offers into one big list
	for (auto& offerSet : offers) {
		for (size_t offer : offerSet.second)
			consideredOffers.emplace_back(offerSet.first, offer);
	}

	// We can free up the offers vector. We're all done with it.
	// TODO: Should we do this? Could be shooting ourselves in the foot
	//       if we forget later. Oh well.
	offers.clear();
	offers.shrink_to_fit();

	// Lets's sort all of our offers by how popular they are
	sort(begin(consideredOffers), end(consideredOffers), [&] (const Offer& a, const Offer& b) {
		return popularity[a.chunkIdx].second < popularity[b.chunkIdx].second;
	});
}
开发者ID:mrkline,项目名称:torrential,代码行数:31,代码来源:Peer.cpp

示例5: end_train

void end_train(void) {
  ds = new AnnoyIndex<int, int64_t, Hamming, Kiss32Random>((pointset[0]).size());
  for (int i = 0; i < pointset.size(); i++) {
	ds->add_item(i, mapEntry(pointset[i]));
  }
  pointset.clear();
  pointset.shrink_to_fit();
  ds->build(num_trees);
}
开发者ID:maumueller,项目名称:ann-benchmarks,代码行数:9,代码来源:lib-annoy-hamming.cpp

示例6: window_install_track_close

/**
 *
 *  rct2: 0x006D41DC
 */
static void window_install_track_close(rct_window* w)
{
    _trackPath.clear();
    _trackName.clear();
    _trackDesignPreviewPixels.clear();
    _trackDesignPreviewPixels.shrink_to_fit();
    track_design_dispose(_trackDesign);
    _trackDesign = nullptr;
}
开发者ID:OpenRCT2,项目名称:OpenRCT2,代码行数:13,代码来源:InstallTrack.cpp

示例7: FixColFile

/*
 *  FixColFile
 *      Fixes the COLFILE from gta.dat not working properly, crashing the game.
 */
void FixColFile()
{
    static bool using_colbuf;           // Is using colbuf or original buffer?
    static bool empty_colmodel;         // Is this a empty colmodel?
    static std::vector<char> colbuf;    // Buffer for reading col file into

    // Prototype for patches
    using rcolinfo_f  = int(void*, uint32_t*, size_t);
    using rcolmodel_f = int(void*, char*, size_t);
    using lcol_f      = int(char*, int, void*, char*);
    using rel_f       = int(void*);

    // Fixes the crash caused by using COLFILE for a building etc
    ColModelPool_new = MakeCALL(0x5B4F2E, HOOK_LoadColFileFix).get();

    // Reads collision info and check if we need to use our own collision buffer
    auto ReadColInfo = [](std::function<rcolinfo_f> Read, void*& f, uint32_t*& buffer, size_t& size)
    {
        auto r    = Read(f, buffer, size);
        empty_colmodel = (buffer[1] <= 0x18);
        if(using_colbuf = !empty_colmodel)
            colbuf.resize(buffer[1]);
        return r;
    };

    // Replace buffer if necessary
    auto ReadColModel = [](std::function<rcolmodel_f> Read, void*& f, char*& buffer, size_t& size)
    {
        if(!empty_colmodel)
            return Read(f, using_colbuf? colbuf.data() : buffer, size);
        return 0;
    };

    // Replace buffer if necessary
    auto LoadCollisionModel = [](std::function<lcol_f> LoadColModel, char*& buf, int& size, void*& colmodel, char*& modelname)
    {
        return LoadColModel(using_colbuf? colbuf.data() : buf, size, colmodel, modelname);
    };

    // Frees our buffer
    auto ReleaseBuffer = [](std::function<rel_f> fclose, void*& f)
    {
        colbuf.clear(); colbuf.shrink_to_fit();
        return fclose(f);
    };

    // Patches
    make_static_hook<function_hooker<0x5B4EF4, rcolmodel_f>>(ReadColModel);
    make_static_hook<function_hooker<0x5B4E92, rcolinfo_f>>(ReadColInfo);
    make_static_hook<function_hooker<0x5B4FCC, rcolinfo_f>>(ReadColInfo);
    make_static_hook<function_hooker<0x5B4FA0, lcol_f>>(LoadCollisionModel);
    make_static_hook<function_hooker<0x5B4FB5, lcol_f>>(LoadCollisionModel);
    make_static_hook<function_hooker<0x5B4F83, lcol_f>>(LoadCollisionModel);
    make_static_hook<function_hooker<0x5B92F9, rel_f>>(ReleaseBuffer);
}
开发者ID:victor2566,项目名称:modloader,代码行数:59,代码来源:data.cpp

示例8: loadNodesFromFile

/**
 * Reads the beginning of an .osrm file and produces:
 *  - list of barrier nodes
 *  - list of traffic lights
 *  - nodes indexed by their internal (non-osm) id
 */
NodeID loadNodesFromFile(std::istream &input_stream,
                         std::vector<NodeID> &barrier_node_list,
                         std::vector<NodeID> &traffic_light_node_list,
                         std::vector<extractor::QueryNode> &node_array)
{
    const FingerPrint fingerprint_valid = FingerPrint::GetValid();
    FingerPrint fingerprint_loaded;
    input_stream.read(reinterpret_cast<char *>(&fingerprint_loaded), sizeof(FingerPrint));

    if (!fingerprint_loaded.TestContractor(fingerprint_valid))
    {
        SimpleLogger().Write(logWARNING) << ".osrm was prepared with different build.\n"
                                            "Reprocess to get rid of this warning.";
    }

    NodeID n;
    input_stream.read(reinterpret_cast<char *>(&n), sizeof(NodeID));
    SimpleLogger().Write() << "Importing n = " << n << " nodes ";

    extractor::ExternalMemoryNode current_node;
    for (NodeID i = 0; i < n; ++i)
    {
        input_stream.read(reinterpret_cast<char *>(&current_node),
                          sizeof(extractor::ExternalMemoryNode));
        node_array.emplace_back(current_node.lon, current_node.lat, current_node.node_id);
        if (current_node.barrier)
        {
            barrier_node_list.emplace_back(i);
        }
        if (current_node.traffic_lights)
        {
            traffic_light_node_list.emplace_back(i);
        }
    }

    // tighten vector sizes
    barrier_node_list.shrink_to_fit();
    traffic_light_node_list.shrink_to_fit();

    return n;
}
开发者ID:james-gould,项目名称:osrm-backend,代码行数:47,代码来源:graph_loader.hpp

示例9: createSearchKey

void createSearchKey(unsigned int numberRows, unsigned int NBFS, std::vector<int> &search_key, const Eigen::SparseMatrix<int> &EdgeMatrix)
{

//columndegree contains number of nonzeros per column
//for removing searchkey values that are not connected to main graph
    std::vector<int> columndegree;
    columndegree.reserve(numberRows);

    for (unsigned int i = 0; i < numberRows; i++)
    {
        columndegree.push_back(EdgeMatrix.outerIndexPtr()[i+1]-EdgeMatrix.outerIndexPtr()[i]);
    }

//generate search key values based on time seed
    std::mt19937 generator(std::chrono::system_clock::now().time_since_epoch()/std::chrono::seconds(1));

    std::cout << "creating search key vector" << std::endl;
    for (unsigned int i = 0; i < numberRows; i++)
    {
        search_key.push_back(i);
    }
//shuffle search key values
    std::shuffle(search_key.begin(),search_key.end(),generator);

//take first 64 or entire search key, whichever is smaller
    if (search_key.size() > NBFS)
    {
        for (unsigned int i = 0; i < NBFS+20; i++)
        {
            //remove search key values that aren't connected to main graph
            if (columndegree.at(search_key.at(i)) == 0)
            {
                search_key.erase(search_key.begin()+i);
                i--;
            }
        }
        search_key.erase(search_key.begin()+NBFS, search_key.end());
    }

    std::cout << "Removing search keys with no edges" << std::endl;
    for (unsigned int i = 0; i < search_key.size(); i++)
    {
        //remove search key values that aren't connected to main graph
        if (columndegree.at(search_key.at(i)) == 0)
        {
            search_key.erase(search_key.begin()+i);
            i--;
        }
    }

    search_key.shrink_to_fit();
}
开发者ID:cwmoo740,项目名称:graph500,代码行数:52,代码来源:createSearchKey.cpp

示例10:

inline static void alacv_get_nodes(std::vector<int> &node_set, bool ready)
{
	node_set.clear();
	for(std::size_t i = 0, max_i = _alacrity_vector.size(); i < max_i; ++i)
	{
		flag_t flag_block = _alacrity_vector[i];
		for (std::size_t j = 0, max_j = min(_max_flag_count, FLAG_TYPE_BIT_COUNT); j < max_j; ++j)
		{
			if ((flag_block & (__ROTATE_LEFT(1, j))) == static_cast<unsigned int>(ready)) node_set.push_back(i * FLAG_TYPE_BIT_COUNT + j);
		}
	}
	node_set.shrink_to_fit();
}
开发者ID:vrishe,项目名称:mpi-benchmarks,代码行数:13,代码来源:MPIMassOperationEmulator.cpp

示例11: window_track_place_close

/**
 *
 *  rct2: 0x006D0119
 */
static void window_track_place_close(rct_window *w)
{
    window_track_place_clear_provisional();
    viewport_set_visibility(0);
    map_invalidate_map_selection_tiles();
    gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_CONSTRUCT;
    gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_ARROW;
    hide_gridlines();
    _window_track_place_mini_preview.clear();
    _window_track_place_mini_preview.shrink_to_fit();
    track_design_dispose(_trackDesign);
    _trackDesign = nullptr;
}
开发者ID:Gymnasiast,项目名称:OpenRCT2,代码行数:17,代码来源:TrackDesignPlace.cpp

示例12: clear

 void clear()
 {
     // Delete[]'ing ptr's to all Buckets
     for (auto bucket : bucket_list)
     {
         if (nullptr != bucket)
         {
             delete[] bucket;
             bucket = nullptr;
         }
     }
     bucket_list.clear();
     bucket_list.shrink_to_fit();
     current_size = 0;
 }
开发者ID:089,项目名称:osrm-backend,代码行数:15,代码来源:deallocating_vector.hpp

示例13: Terminate

void Terminate()
{		
	TwTerminate();

	glDeleteBuffers(1, &Material::UBO);
	glDeleteBuffers(1, &PointLight::UBO);
	glDeleteBuffers(1, &g_Camera.UBO);

	g_Spheres.shrink_to_fit();
	
	CleanMesh(g_SphereMesh);

	glDeleteTextures(3, g_Walls.textures);
	CleanMesh(g_WallMesh);

	g_BlinnPhongShader.Destroy();
	g_AmbientShader.Destroy();
}
开发者ID:VisualPi,项目名称:ESGI_COURS_VISUALPI,代码行数:18,代码来源:MultiplePointLights.cpp

示例14: unique

void algorithms::KDDecomposer<IROBOT>::get_unique_crn_cfgs(std::vector<const CONFIG*>& result, std::vector<CONFIG>& all_corners) const
{
    std::clock_t    t0 = std::clock();
    for (const Cell<IROBOT>& cell : cells) {
        cell.get_corner_configs(all_corners);
    }
    all_corners.shrink_to_fit();
    const CONFIG** temp = new const CONFIG*[all_corners.size()];
    
    for (int i = 0; i < all_corners.size(); ++i)
        temp[i] = &all_corners[i];
    
    std::sort(temp, temp + all_corners.size(),  IROBOT::cmp);
    const CONFIG** end = unique( temp, temp + all_corners.size(), IROBOT::approximate);
    result.insert(result.begin(), temp, end);
    delete[] temp;
    std::clock_t    t1 = std::clock();
}
开发者ID:Yinan-Zhang,项目名称:MetricCells,代码行数:18,代码来源:cspace_decomposer.cpp

示例15: primeList

void primeList(std::vector<unsigned int> &rvPrimes){
	unsigned int loc = 0, sz = rvPrimes.size();	// 'loc' is current place in vector
	int pVal;

	#define D(i) C(loc, i, pVal)

	while (loc < sz){
		if (rvPrimes[loc]){
			pVal = rvPrimes[loc];
			for (unsigned int i = 1; D(i) < sz; ++i)
				rvPrimes[D(i)] = 0;
		}
		loc++;
	}
	rvPrimes.erase(std::remove(std::begin(rvPrimes), std::end(rvPrimes), 0), std::end(rvPrimes));	//erase-remove idiom; removes all 0s
	rvPrimes.shrink_to_fit();	//free up a little memory by reducing capacity() down to actual size()

	return;
}
开发者ID:TheEyesightDim,项目名称:EulerProblems,代码行数:19,代码来源:primelister.cpp


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