本文整理汇总了C++中TreeIterator类的典型用法代码示例。如果您正苦于以下问题:C++ TreeIterator类的具体用法?C++ TreeIterator怎么用?C++ TreeIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TreeIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BinarizeRandomly
void Node::BinarizeRandomly()
{
TreeIterator* it = this->GetPostOrderIterator();
while (Node* n = it->next())
{
if (n != this)
{
n->BinarizeRandomly();
}
}
this->CloseIterator(it);
while (this->GetNbChildren() > 2)
{
int ic1 = rand() % this->GetNbChildren();
int ic2 = rand() % this->GetNbChildren();
if (ic1 != ic2)
{
Node* c1 = this->GetChild(ic1);
Node* c2 = this->GetChild(ic2);
c1->InsertParentWith(c2);
}
}
}
示例2: GetEdgeType
string SADNADGraph::GetEdgeType(Node* n1, Node* n2, unordered_map<Node*, Node*> &lcaMapping)
{
Node* s1 = lcaMapping[n1];
Node* s2 = lcaMapping[n2];
if (!s1->HasAncestor(s2) && !s2->HasAncestor(s1))
{
return "S";
}
else
{
bool hasOne = false;
unordered_set<Node*> n1Species = GeneSpeciesTreeUtil::Instance()->GetGeneTreeSpecies(n1, lcaMapping);
TreeIterator* it = n2->GetPostOrderIterator(true);
while (Node* n2leaf = it->next())
{
if (n1Species.find(lcaMapping[n2leaf]) != n1Species.end())
{
hasOne = true;
break;
}
}
n2->CloseIterator(it);
if (hasOne)
return "AD";
else
return "NAD";
}
}
示例3:
status_t
Directory::Rewind(void *cookie)
{
TreeIterator *iterator = (TreeIterator *)cookie;
return iterator->Rewind();
}
示例4: GetNodeWithLabel
Node* Node::GetNodeWithLabel(string lbl, bool ignoreCase)
{
TreeIterator* it = this->GetPostOrderIterator();
Node* found = NULL;
while (Node* n = it->next())
{
if (ignoreCase)
{
if (Util::ToUpper(lbl) == Util::ToUpper(n->GetLabel()))
{
found = n;
break;
}
}
else
{
if (lbl == n->GetLabel())
{
found = n;
break;
}
}
}
this->CloseIterator(it);
return found;
}
示例5: make_pair
pair<Node*, unordered_map<Node*, Node*> > PolySolverNAD::PolytomizeNAD(Node* nadNode, Node* speciesTree, unordered_map<Node*, Node*> lcaMapping)
{
set<Node*> leftSubtrees, rightSubtrees;
Node* s = lcaMapping[nadNode];
//TODO : there should be a way not to iterate uselessly into a taken subtree (preorder traversal that we stop)
TreeIterator* it = nadNode->GetPostOrderIterator();
while (Node* n = it->next())
{
if (n != nadNode)
{
//here we maximal subtree either on the left or right
if (lcaMapping[n] != s && lcaMapping[n->GetParent()] == s)
{
if (lcaMapping[n]->HasAncestor(s->GetChild(0)))
{
leftSubtrees.insert(n);
}
else //if (lcaMapping[n]->HasAncestor(s->GetChild(1))) should be the only possibility here
{
rightSubtrees.insert(n);
}
}
}
}
nadNode->CloseIterator(it);
Node* newShizzle = new Node(false);
Node* left = newShizzle->AddChild();
Node* right = newShizzle->AddChild();
unordered_map<Node*, Node*> newMapping;
for (set<Node*>::iterator itLeft = leftSubtrees.begin(); itLeft != leftSubtrees.end(); itLeft++)
{
Node* copy = GeneSpeciesTreeUtil::Instance()->CopyTreeWithNodeMapping((*itLeft), lcaMapping, newMapping);
left->AddSubTree(copy);
}
for (set<Node*>::iterator itRight = rightSubtrees.begin(); itRight != rightSubtrees.end(); itRight++)
{
Node* copy = GeneSpeciesTreeUtil::Instance()->CopyTreeWithNodeMapping((*itRight), lcaMapping, newMapping);
right->AddSubTree(copy);
}
newMapping[newShizzle] = s;
if (left->GetNbChildren() > 1)
{
newMapping[left] = GeneSpeciesTreeUtil::Instance()->GetSingleNodeLCAMapping(left, speciesTree, newMapping);
}
if (right->GetNbChildren() > 1)
{
newMapping[right] = GeneSpeciesTreeUtil::Instance()->GetSingleNodeLCAMapping(right, speciesTree, newMapping);
}
newShizzle->DeleteSingleChildDescendants();
return make_pair(newShizzle, newMapping);
}
示例6: testItr
void testItr( TreeIterator<Object> & itr )
{
try
{
for( itr.first( ); itr.isValid( ); itr.advance( ) )
cout << itr.retrieve( ) << "*";
cout << endl;
}
catch( BadIterator & e )
{ cout << e.toString( ) << endl; }
}
示例7: getMenuTreeNodeSibling
/*---------------------------------------------------------------------*//**
兄弟ノード取得
**//*---------------------------------------------------------------------*/
MenuTreeNode* Menu::getMenuTreeNodeSibling(MenuTreeNode* mtnode) const
{
for(TreeIterator<MenuTreeNode> it = _tree->iterator(); it.has(); it.next())
{
if(it.object() == mtnode)
{
TreeNode<MenuTreeNode>* tnodeSibling = it.node()->sibling();
return (tnodeSibling != 0L) ? tnodeSibling->object() : 0L;
}
}
return 0L;
}
示例8: while
vector<Node*> Node::GetPostOrderedNodes()
{
vector<Node*> v;
TreeIterator* it = this->GetPostOrderIterator();
while (Node* n = it->next())
{
v.push_back(n);
}
this->CloseIterator(it);
return v;
}
示例9: getMenuTreeNodeChild
/*---------------------------------------------------------------------*//**
子ノード取得
**//*---------------------------------------------------------------------*/
MenuTreeNode* Menu::getMenuTreeNodeChild(MenuTreeNode* mtnode) const
{
for(TreeIterator<MenuTreeNode> it = _tree->iterator(); it.has(); it.next())
{
if(it.object() == mtnode)
{
TreeNode<MenuTreeNode>* tnodeChild = it.node()->child();
return (tnodeChild != 0L) ? tnodeChild->object() : 0L;
}
}
return 0L;
}
示例10: sizeof
status_t
Directory::GetNextNode(void *cookie, Node **_node)
{
TreeIterator *iterator = (TreeIterator *)cookie;
char name[B_FILE_NAME_LENGTH];
uint16 length;
off_t id;
status_t status = iterator->GetNextEntry(name, &length, sizeof(name), &id);
if (status != B_OK)
return status;
*_node = Stream::NodeFactory(fStream.GetVolume(), id);
if (*_node == NULL)
return B_ERROR;
return B_OK;
}
示例11: DeleteSingleChildDescendants
void Node::DeleteSingleChildDescendants()
{
TreeIterator* it = this->GetPostOrderIterator();
Node* n = it->next();
while (n)
{
if (n->GetNbChildren() == 1)
{
n = it->DeleteCurrent();
}
else
{
n = it->next();
}
}
this->CloseIterator(it);
}
示例12: while
bool Menu::createFromXml(FileBase* fileXml, MenuFuncTable* functblRef, MenuPanelFactory* pnlfctryRef, void* objCreateParam)
{
// XML ファイルをバッファに読み込む
VcString bufFile;
while(true)
{
const int SIZE_BUF = 100 * 1024;
char buf[SIZE_BUF];
int sizeRead = fileXml->read(buf, SIZE_BUF);
bufFile.add(buf, sizeRead);
if(sizeRead < SIZE_BUF) { break; }
}
CMXML_TRACE(VcString::format("{Menu::createFromXml} menu xml : size=%d\n", bufFile.getLength()));
// XML を解析する
XmlParser xmlparser;
xmlparser.parseXmlDocument(&bufFile);
CMXML_TRACE("{Menu::createFromXml} XmlParser::parseXmlDocument end.\n");
// ツリーを作成する
_tree = new Tree<MenuTreeNode>(true);
addTreeNode(_tree->addRootNode(), true, xmlparser.getRootNode());
#if defined(_DEBUG)
TRACE("{Menu::createFromXml} menu hierarchy\n");
for(TreeIterator<MenuTreeNode> it = _tree->iterator(); it.has(); it.next())
{
if(it.object() != 0L) { for(int i = 0; i < it.getDepth(); i++) { CMXML_TRACE(" "); } CMXML_TRACE( *it.object()->getName() + "\n" ); }
}
#endif
// ファンクションテーブルを保存する
_functblRef = functblRef;
// パネルファクトリを保存する
_pnlfctryRef = pnlfctryRef;
// パラメータオブジェクトを保存する
_objCreateParamRef = objCreateParam;
return true;
}
示例13: closeMenu
/*---------------------------------------------------------------------*//**
破棄
**//*---------------------------------------------------------------------*/
void Menu::destroy()
{
if(_isShow)
{
closeMenu();
}
// ツリー削除
if(_tree != 0L)
{
for(TreeIterator<MenuTreeNode> it = _tree->iterator(); it.has(); it.next())
{
MenuTreeNode* mtnode = it.object();
if(mtnode != 0L) // ルートは NULL
{
mtnode->destroy();
}
}
delete _tree;
_tree = 0L;
}
}
示例14: Restrict
void Node::Restrict(bool (*fncDelete)(Node*, void*), void* arg)
{
TreeIterator* it = this->GetPostOrderIterator();
Node* n = it->next();
while (n)
{
bool ok = (*fncDelete)(n, arg);
if (!ok)
{
n = it->DeleteCurrent();
}
else
{
n = it->next();
}
}
this->CloseIterator(it);
}
示例15: SolvePolytomies
Node* PolySolverNAD::SolvePolytomies(Node *geneTree, Node *speciesTree, unordered_map<Node*, Node*> geneLeavesSpeciesMapping)
{
//TODO : THIS HASN'T BEEN TESTED AFTER SOME MODIFICATIONS !!
Node* geneTreeCopy;
unordered_map<Node*, Node*> mappingCopy;
geneTreeCopy = GeneSpeciesTreeUtil::Instance()->CopyTreeWithNodeMapping(geneTree, geneLeavesSpeciesMapping, mappingCopy);
unordered_map<Node*, Node*> lcaMapping = GeneSpeciesTreeUtil::Instance()->GetLCAMapping(geneTreeCopy, speciesTree, mappingCopy);
TreeIterator* it = geneTreeCopy->GetPostOrderIterator();
while (Node* g = it->next())
{
vector<Node*> curLeaves;
for (int i = 0; i < g->GetNbChildren(); i++)
{
curLeaves.push_back(g->GetChild(i));
}
this->SolvePolytomy(curLeaves, speciesTree, lcaMapping);
}
return geneTreeCopy;
}