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


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

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


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

示例1: PMap

 void PMap(const NodeMap& m)
 {
   // print out map
   NodeMap::const_iterator it;
   pout() << "Node map has " << m.size() << " nodes\n";
   for (it=m.begin(); it!=m.end(); it++)
   {
     pout() << "node "; PIV(it->first); pout() << ": " << it->second << "\n";
   }
 }
开发者ID:dtgraves,项目名称:EBAMRCNS,代码行数:10,代码来源:STLUtil.cpp

示例2: MakeCloseTarget

CUInt128 CKademlia::MakeCloseTarget(int *pDistance)
{
	if(!m_pKadHandler)
	{
		if(pDistance)
			*pDistance = -1;
		return 0;
	}

	CUInt128 uMyID = m_pRootZone->GetID();
	NodeMap Nodes;
	m_pRootZone->GetClosestNodes(uMyID, Nodes, Cfg()->GetInt("BucketSize"));
	if(Nodes.size() < 2)
	{
		if(pDistance)
			*pDistance = -1;
		return 0;
	}
	
	// Find Median distance difference between nodes closest to us
	vector<CUInt128> Diff;
	for(NodeMap::iterator np = Nodes.begin(), n = np++; np != Nodes.end(); n = np++)
		Diff.push_back(np->first - n->first);
	CUInt128 Sep = Median(Diff);

	// generate ID that is closer to us than the closest node by a few difference
	CUInt128 uDistance = Nodes.begin()->first;
	for(int i=0; i < 3 && uDistance > Sep; i++)
		uDistance = uDistance - Sep;
	CUInt128 uCloser = uMyID ^ uDistance;

	// count the matchign bits
	UINT uLevel=0;
	for(; uLevel < uMyID.GetBitSize(); uLevel++)
	{
		if(uCloser.GetBit(uLevel) != uMyID.GetBit(uLevel))
			break;
	}

	// add a few more matching bytes
	for(UINT i=0; i < 4 && uLevel < uMyID.GetBitSize() - 1; i++)
	{
		uCloser.SetBit(uLevel, uMyID.GetBit(uLevel));
		uLevel++;
	}

	if(pDistance)
		*pDistance = (int)uMyID.GetBitSize() - uLevel;

	// create a random ID that we are closest to
	CUInt128 uRandom(uCloser, uLevel);
	//wstring sTest = (uMyID ^ uRandom).ToBin();
	return uRandom;
}
开发者ID:0vermind,项目名称:NeoLoader,代码行数:54,代码来源:Kademlia.cpp

示例3: readProjectionsInfo

void FileProjections::readProjectionsInfo()
{
    // Prepare nodes
    NodeMap* nodeList = graph->getNodeMap();
    unsigned count = nodeList->size();

    if (!count)
        return;

    unsigned oldSize = projectionsList->size();
    bool isProjectionsWasEmpty = !oldSize;

    projectionsList->resize(count, nullptr);
    projectionsList->shrink_to_fit();

    auto oldStart = projectionsList->begin();
    auto oldEnd = projectionsList->begin() + oldSize;
    auto it = nodeList->begin();
    Projection* pr;

    ProjectionsReader reader(*this);
    std::string saveName(graphFileName);
    unsigned nameSize = saveName.size();
    bool someMissing = false, someReaded = false;

    startProcess(0u, count - 1);

    unsigned currentId;
    unsigned pos = oldSize;

    for(unsigned i = 0u; i < count; ++i, ++it)
    {
        if (isInterrupted())
        {
            projectionStatus = Status::PARTIAL;
            return;
        }

        updateProgress(i);

        currentId = it->first;
        pr = nullptr;
        // Projection exist - skip
        if (!isProjectionsWasEmpty)
        {
            auto e = std::lower_bound(oldStart, oldEnd, currentId,
                                      Projection::lessById);
            if (e != oldEnd && (*e)->getId() == currentId)
            {
                pr = *e;
            }
        }
        if (!pr)
        {
            pr = new Projection(currentId);
            (*projectionsList)[pos] = pr;
            ++pos;
        }

        ProjectionsReader::projectionFileName(saveName, nameSize, currentId);

        bool result = reader.readProjectionInfo(saveName.data(), pr);
        if (result)
        {
            someReaded = true;
        }
        else
        {
            someMissing = true;
            if (reader.getLastError() == ProjectionsReader::Error::TYPE)
            {
                lastError = Error::TYPE;
            }
        }
    }
    if (someReaded)
    {
        projectionStatus = someMissing ? Status::PARTIAL : Status::ALL;
    }
    else
    {
        projectionStatus = Status::EMPTY;
    }

    // check that list was not empty and some new projections added
    if (oldSize && oldSize != count)
    {
        auto end = projectionsList->end();
        std::sort(oldStart, end, Projection::less);
    }
    completeProcess();
}
开发者ID:Savelyev-Aleksey,项目名称:Compact-graph,代码行数:92,代码来源:FileProjections.cpp

示例4: createAllProjections

void FileProjections::createAllProjections()
{
    if (graph->isEmpty())
    {
        return;
    }

    if(isMemoryUsed())
    {
        Projections::createAllProjections();
        return;
    }

    // Prepare nodes
    NodeMap* nodeList = graph->getNodeMap();
    unsigned count = nodeList->size();

    if (!count)
        return;

    ProjectionsWriter writer(*this);
    setWorker(&writer, true);
    startProcess(0u, count - 1);

    unsigned oldSize = projectionsList->size();
    bool isWasEmpty = !oldSize;

    projectionsList->resize(count, nullptr);
    projectionsList->shrink_to_fit();

    auto oldStart = projectionsList->begin();
    auto oldEnd = projectionsList->begin() + oldSize;
    auto it = nodeList->begin();
    Projection* pr;

    std::string saveName(graphFileName);
    unsigned nameSize = saveName.size();

    unsigned currentId;
    unsigned pos = oldSize;

    for(unsigned i = 0u; i < count; ++i, ++it)
    {
        if (isInterrupted())
        {
            projectionStatus = Status::PARTIAL;
            // if interrupted on null filled projections, shrink list
            projectionsList->resize(pos);
            break;
        }

        updateProgress(i);

        currentId = it->first;
        pr = nullptr;
        // Projection exist - skip
        if (!isWasEmpty)
        {
            auto e = std::lower_bound(oldStart, oldEnd, currentId,
                                      Projection::lessById);
            if (e != oldEnd && (*e)->getId() == currentId)
            {
                pr = *e;
                if (pr->fileExist())
                    continue;
            }
        }
        if (!pr)
        {
            pr = new Projection(currentId);
            (*projectionsList)[pos] = pr;
            ++pos;
        }
        pr->createProjection(*graph);
        if (pr->isInterrupted())
        {
            continue;
        }

        ProjectionsReader::projectionFileName(saveName, nameSize, currentId);

        bool result = writer.saveProjection(saveName.data(), pr);

        if (result)
        {
            pr->setFileExist(true);
        }
        // stay loaded last projection
        if (count - i > 1)
        {
            pr->clear();
        }
        else
        {
            loadedProjection = pr;
        }
    }

    if (!isWasEmpty)
    {
//.........这里部分代码省略.........
开发者ID:Savelyev-Aleksey,项目名称:Compact-graph,代码行数:101,代码来源:FileProjections.cpp

示例5: startElement

void UtilOSMVisitor::startElement(const char *name, const XMLAttributes &atts)
{
	const char *val;

	if (m_state == 0)
	{
		if (!strcmp(name, "node"))
		{
			DPoint2 p;

			val = atts.getValue("id");
			if (val)
				m_id = atoi(val);
			else
				m_id = -1;	// Shouldn't happen.

			val = atts.getValue("lon");
			if (val)
				p.x = atof(val);

			val = atts.getValue("lat");
			if (val)
				p.y = atof(val);

			OSMNode node;
			node.p = p;
			m_nodes[m_id] = node;

			m_state = PS_NODE;

			m_pole = NULL;
		}
		else if (!strcmp(name, "way"))
		{
			m_refs.clear();
			m_state = PS_WAY;
			val = atts.getValue("id");
			if (val)
				m_id = atoi(val);
			else
				m_id = -1;	// Shouldn't happen.

			// Defaults
			m_line = NULL;
		}
	}
	else if (m_state == PS_NODE && !strcmp(name, "tag"))
	{
		vtString key, value;

		val = atts.getValue("k");
		if (val)
			key = val;

		val = atts.getValue("v");
		if (val)
			value = val;

		if (key == "power" && value == "tower")
			StartPowerPole();

		// Node key/value
		else if (key == "highway")
		{
			if (value == "traffic_signals")
			{
				m_nodes[m_nodes.size()-1].signal_lights = true;
			}
		}
		else if (m_pole)
		{
			// Add all node tags for power towers
			m_pole->AddTag(key, value);
		}
	}
	else if (m_state == PS_WAY)
	{
		if (!strcmp(name, "nd"))
		{
			val = atts.getValue("ref");
			if (val)
			{
				int ref = atoi(val);
				m_refs.push_back(ref);
			}
		}
		else if (!strcmp(name, "tag"))
		{
			vtString key, value;

			val = atts.getValue("k");
			if (val)
				key = val;

			val = atts.getValue("v");
			if (val)
				value = val;

			if (m_line)
				m_line->AddTag(key, value);
//.........这里部分代码省略.........
开发者ID:kamalsirsa,项目名称:vtp,代码行数:101,代码来源:UtilityMap.cpp

示例6: outfile

int
main (int   argc,
      char* argv[])
{
    BoxLib::Initialize(argc,argv);

    if (argc < 2)
        print_usage(argc,argv);

    ParmParse pp;

    if (pp.contains("help"))
        print_usage(argc,argv);

    bool verbose = false;
    pp.query("verbose",verbose);

    if (verbose>1)
        AmrData::SetVerbose(true);

    std::string infile; pp.get("infile",infile);
    std::string outfile_DEF;

    std::string outType = "tec";
#ifdef USE_TEC_BIN_IO
    bool doBin = true;
    pp.query("doBin",doBin);
    outfile_DEF = infile+(doBin ? ".plt" : ".dat" );
#else
    bool doBin=false;
    outfile_DEF = infile+".dat";
#endif

    // 
    bool connect_cc = true; pp.query("connect_cc",connect_cc);

    std::string outfile(outfile_DEF); pp.query("outfile",outfile);
    DataServices::SetBatchMode();
    Amrvis::FileType fileType(Amrvis::NEWPLT);
    DataServices dataServices(infile, fileType);

    if (!dataServices.AmrDataOk())
        DataServices::Dispatch(DataServices::ExitRequest, NULL);

    AmrData& amrData = dataServices.AmrDataRef();

    const Array<std::string>& names = amrData.PlotVarNames();

    Array<int> comps;
    if (int nc = pp.countval("comps"))
    {
        comps.resize(nc);
        pp.getarr("comps",comps,0,nc);
    }
    else
    {
        int sComp = 0;
        pp.query("sComp",sComp);
        int nComp = amrData.NComp();
        pp.query("nComp",nComp);
        BL_ASSERT(sComp+nComp <= amrData.NComp());
        comps.resize(nComp);
        for (int i=0; i<nComp; ++i)
            comps[i] = sComp + i;
    }

    Box subbox;
    if (int nx=pp.countval("box"))
    {
        Array<int> barr;
        pp.getarr("box",barr,0,nx);
        int d=BL_SPACEDIM;
        BL_ASSERT(barr.size()==2*d);
        subbox=Box(IntVect(D_DECL(barr[0],barr[1],barr[2])),
                   IntVect(D_DECL(barr[d],barr[d+1],barr[d+2]))) & amrData.ProbDomain()[0];

    } else {

        subbox = amrData.ProbDomain()[0];
    }

    int finestLevel = amrData.FinestLevel(); pp.query("finestLevel",finestLevel);
    int Nlev = finestLevel + 1;
    Array<BoxArray> gridArray(Nlev);
    Array<Box> subboxArray(Nlev);

    int nGrowPer = 0; pp.query("nGrowPer",nGrowPer);
    PArray<Geometry> geom(Nlev);

    Array<Real> LO(BL_SPACEDIM,0);
    Array<Real> HI(BL_SPACEDIM,1);
    RealBox rb(LO.dataPtr(),HI.dataPtr());
    int coordSys = 0;
    Array<int> isPer(BL_SPACEDIM,0);

    for (int lev=0; lev<Nlev; ++lev)
    {
        subboxArray[lev]
            = (lev==0 ? subbox
               : Box(subboxArray[lev-1]).refine(amrData.RefRatio()[lev-1]));
//.........这里部分代码省略.........
开发者ID:dwillcox,项目名称:BoxLib,代码行数:101,代码来源:AmrDeriveTecplot.cpp


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