本文整理汇总了C++中NodeMap::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeMap::begin方法的具体用法?C++ NodeMap::begin怎么用?C++ NodeMap::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeMap
的用法示例。
在下文中一共展示了NodeMap::begin方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: HandleNodeReq
void CKadHandler::HandleNodeReq(const CVariant& NodeReq, CKadNode* pNode, CComChannel* pChannel)
{
if(GetParent<CKademlia>()->Cfg()->GetBool("DebugRT"))
LogLine(LOG_DEBUG, L"Recived 'Node Resuest' to %s", pNode->GetID().ToHex().c_str());
CVariant NodeRes;
uint32 uDesiredCount = NodeReq["RCT"];
if(uDesiredCount == 0)
throw CException(LOG_ERROR, L"node requested 0 nodes");
int iMaxState = NodeReq.Get("MNC", NODE_2ND_CLASS);
NodeMap Nodes;
if(!NodeReq.Has("TID"))
GetParent<CKademlia>()->Root()->GetBootstrapNodes(GetParent<CKademlia>()->Root()->GetID(), Nodes, uDesiredCount, pChannel->GetAddress().GetProtocol(), iMaxState);
else
GetParent<CKademlia>()->Root()->GetClosestNodes(NodeReq["TID"], Nodes, uDesiredCount, pChannel->GetAddress().GetProtocol(), iMaxState);
CVariant List;
for(NodeMap::iterator I = Nodes.begin(); I != Nodes.end(); I++)
List.Append(I->second->Store());
NodeRes["LIST"] = List;
if(GetParent<CKademlia>()->Cfg()->GetBool("DebugRT"))
LogLine(LOG_DEBUG, L"Sending 'Node Response' to %s", pNode->GetID().ToHex().c_str());
pChannel->QueuePacket(KAD_NODE_RESPONSE, NodeRes);
}
示例3: prepForTree
static void prepForTree() {
#ifndef VL_LEAK_CHECKS
s_nodes.clear();
#endif
for (NodeMap::iterator it = s_nodes.begin(); it != s_nodes.end(); ++it) {
it->second &= ~FLAG_IN_TREE;
it->second &= ~FLAG_LINKABLE;
}
}
示例4: AddNodes
void CLookupHistory::AddNodes(const NodeMap& Nodes, const CUInt128& ByID)
{
for(NodeMap::const_iterator I = Nodes.begin(); I != Nodes.end(); I++)
{
LookupNodeMap::iterator J = m_Nodes.find(I->second->GetID());
if(J == m_Nodes.end())
J = m_Nodes.insert(LookupNodeMap::value_type(I->second->GetID(), SLookupNode())).first;
J->second.FoundByIDs.push_back(ByID == 0 ? SELF_NODE : ByID);
}
}
示例5: 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";
}
}
示例6: markDOMNodesForDocument
void ScriptInterpreter::markDOMNodesForDocument(Document* doc)
{
NodePerDocMap::iterator dictIt = domNodesPerDocument().find(doc);
if (dictIt != domNodesPerDocument().end()) {
NodeMap* nodeDict = dictIt->second;
NodeMap::iterator nodeEnd = nodeDict->end();
for (NodeMap::iterator nodeIt = nodeDict->begin(); nodeIt != nodeEnd; ++nodeIt) {
DOMNode* node = nodeIt->second;
// don't mark wrappers for nodes that are no longer in the
// document - they should not be saved if the node is not
// otherwise reachable from JS.
if (node->impl()->inDocument() && !node->marked())
node->mark();
}
}
}
示例7: delete
// recursively delete the stmts and subtrees
~TreeNode()
{
for (StmtMap::iterator sit = stmtMap.begin(); sit != stmtMap.end(); ++sit) {
delete sit->second;
}
stmtMap.clear();
for (LoopList::iterator lit = loopList.begin(); lit != loopList.end(); ++lit) {
delete (*lit)->node;
}
loopList.clear();
for (NodeMap::iterator nit = nodeMap.begin(); nit != nodeMap.end(); ++nit) {
delete nit->second;
}
nodeMap.clear();
}
示例8: doneWithTree
static void doneWithTree() {
for (int backs=0; backs<2; backs++) { // Those with backp() are probably under one leaking without
for (NodeMap::iterator it = s_nodes.begin(); it != s_nodes.end(); ++it) {
if ((it->second & FLAG_ALLOCATED)
&& !(it->second & FLAG_IN_TREE)
&& !(it->second & FLAG_LEAKED)
&& (it->first->backp() ? backs==1 : backs==0)) {
// Use only AstNode::dump instead of the virtual one, as there
// may be varp() and other cross links that are bad.
if (v3Global.opt.debugCheck()) {
cerr<<"%Error: LeakedNode"<<(it->first->backp()?"Back: ":": ");
((AstNode*)(it->first))->AstNode::dump(cerr);
cerr<<endl;
V3Error::incErrors();
}
it->second |= FLAG_LEAKED;
}
}
}
}
示例9: apply
void PertyDuplicatePoiOp::apply(shared_ptr<OsmMap>& map)
{
MapProjector::projectToPlanar(map);
boost::uniform_real<> uni(0.0, 1.0);
boost::normal_distribution<> nd;
boost::variate_generator<boost::minstd_rand&, boost::normal_distribution<> > N(*_rng, nd);
// make a copy since we'll be modifying the map as we go.
NodeMap nm = map->getNodeMap();
for (NodeMap::const_iterator it = nm.begin(); it != nm.end(); ++it)
{
if (uni(*_rng) < _p)
{
const NodePtr& n = it->second;
int copies = round(fabs(N() * _duplicateSigma)) + 1;
for (int i = 0; i < copies; i++)
{
duplicateNode(n, map);
}
}
}
}
示例10: 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();
}
示例11: 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)
{
//.........这里部分代码省略.........
示例12: DeleteCFG
/*
* DeleteCFG()
* Remove one CFG.
*/
void DeleteCFG(NodeMap &CFGMap)
{
for (NodeMap::iterator I = CFGMap.begin(), E = CFGMap.end(); I != E; I++)
delete I->first;
}
示例13: removeWrappers
static void removeWrappers(const NodeMap& wrappers)
{
for (NodeMap::const_iterator it = wrappers.begin(); it != wrappers.end(); ++it)
removeWrapper(it->second);
}
示例14: outfile
//.........这里部分代码省略.........
const Node& n2 = ifab(IntVect(iv).shift(BoxLib::BASISV(0)),0);
const Node& n3 = ifab(IntVect(iv).shift(IntVect::TheUnitVector()),0);
const Node& n4 = ifab(IntVect(iv).shift(BoxLib::BASISV(1)),0);
if (n1.type==Node::VALID && n2.type==Node::VALID &&
n3.type==Node::VALID && n4.type==Node::VALID )
elements.insert(Element(n1,n2,n3,n4));
#else
const IntVect& ivu = IntVect(iv).shift(BoxLib::BASISV(2));
const Node& n1 = ifab(iv ,0);
const Node& n2 = ifab(IntVect(iv ).shift(BoxLib::BASISV(0)),0);
const Node& n3 = ifab(IntVect(iv ).shift(BoxLib::BASISV(0)).shift(BoxLib::BASISV(1)),0);
const Node& n4 = ifab(IntVect(iv ).shift(BoxLib::BASISV(1)),0);
const Node& n5 = ifab(ivu,0);
const Node& n6 = ifab(IntVect(ivu).shift(BoxLib::BASISV(0)),0);
const Node& n7 = ifab(IntVect(ivu).shift(BoxLib::BASISV(0)).shift(BoxLib::BASISV(1)),0);
const Node& n8 = ifab(IntVect(ivu).shift(BoxLib::BASISV(1)),0);
if (n1.type==Node::VALID && n2.type==Node::VALID &&
n3.type==Node::VALID && n4.type==Node::VALID &&
n5.type==Node::VALID && n6.type==Node::VALID &&
n7.type==Node::VALID && n8.type==Node::VALID )
elements.insert(Element(n1,n2,n3,n4,n5,n6,n7,n8));
#endif
}
}
}
int nElts = (connect_cc ? elements.size() : nodeMap.size());
std::cerr << "Before connData allocated " << elements.size() << " elements" << endl;
Array<int> connData(MYLEN*nElts);
std::cerr << "After connData allocated " << elements.size() << " elements" << endl;
if (connect_cc) {
cnt = 0;
for (EltSet::const_iterator it = elements.begin(); it!=elements.end(); ++it)
{
for (int j=0; j<MYLEN; ++j)
{
const NodeMap::const_iterator noit = nodeMap.find(*((*it).n[j]));
if (noit == nodeMap.end())
{
std::cout << "Node not found in node map" << std::endl;
std::cout << *((*it).n[j]) << std::endl;
}
else
{
connData[cnt++] = noit->second+1;
}
}
}
} else {
cnt = 1;
for (int i=0; i<nElts; ++i) {
for (int j=0; j<MYLEN; ++j) {
connData[i*MYLEN+j] = cnt++;
}
}
}
std::cerr << "Final elements built" << endl;
// Invert the map
std::vector<Node> nodeVect(nodeMap.size());
for (NodeMap::const_iterator it=nodeMap.begin(); it!=nodeMap.end(); ++it)
{
if (it->second>=nodeVect.size() || it->second<0)
std::cout << "Bad id: " << it->second << " bad node: " << it->first << std::endl;