/** Clean the possible patterns annotations: $enter_new_statement ... */ void clean_pattern(tree<AstNode>& tr) { for (tree<AstNode>::iterator iter=tr.begin(); iter!=tr.end(); ++iter) { if (iter->getType() == "text" && iter->getValue() == "$enter_the_new_statement") { iter = rewind(iter, "statement", tr); tr.erase(iter); break; } } }
void CFileTree::RemoveItem(char *absolutePath) { tree_node_<FILE_ITEM>* node = findNodeFromRootWithPath(absolutePath); if (node != NULL) { filesTree.erase(tree<FILE_ITEM>::iterator(node)); } else { //printf("Do not find node for path : %s\n", absolutePath); } DisplayTree(topNode.node, 0); }
typename tree<T>::iterator remove_if (tree <T> & Q, typename tree<T>::iterator n, bool (*pred_fun) (T) ) { typename tree<T>::iterator c ; if (pred_fun (*n) ) n = Q.erase(n); else { c = n.lchild(); while (c != Q.end()) c = remove_if (Q, c, pred_fun); n++; } // end if return n; }
void mergeNodes(tree<T> &intree) { // First, determine which top node has the shallowest depth int minimal_d(1000); for(typename tree<T>::leaf_iterator c = intree.begin_leaf();c != intree.end_leaf();++c){ int this_depth(intree.depth(c)); if(this_depth < minimal_d) minimal_d = this_depth; } // End c if(minimal_d == -1) return; typedef std::map<T, typename tree<T>::iterator> Info; auto now(intree.begin()); //const int max_depth(intree.max_depth()-1); const int max_depth(minimal_d); for(int depth = 0;depth < max_depth;++depth){ typename tree<T>::fixed_depth_iterator itr_begin(intree.begin_fixed(intree.begin(), depth)); Info siblings; while(intree.is_valid(itr_begin)){ int counts(siblings.count(*itr_begin)); typename tree<T>::fixed_depth_iterator itr_next(intree.next_at_same_depth(itr_begin)); // If current node and the next node are same, combine them if(!counts){ typename tree<T>::iterator current(itr_begin); siblings.insert(typename Info::value_type(*itr_begin, current)); } // End if else{ typename tree<T>::iterator current(itr_begin); typename tree<T>::iterator next(siblings[*itr_begin]); intree.merge(intree.begin(next), intree.end(next), intree.begin(current), intree.end(current)); #ifdef _DEBUG_TREE std::cout << "C: " << *current << " == N: " << *next << std::endl; #endif typename tree<T>::iterator c_back(itr_begin); const int mydepth(intree.depth(c_back)); c_back -= mydepth; intree.erase(c_back); // Erase the redundunt nodes } // End else itr_begin = itr_next; } // End while } // End depth }
/*! * \fn static void CleanUpFormTag(tree<HTML::Node> &m_TagTree); * \brief 剪枝,去除scrip等无用节点 * \param [in]DOM树 * \return void * \date 2011-06-01 * \author nanjunxiao */ void Pretreat::CleanUpFormTag(tree<HTML::Node> &m_TagTree) { set<string> m_sCleanFormSet; m_sCleanFormSet.insert("input"); m_sCleanFormSet.insert("noembed"); m_sCleanFormSet.insert("noscript"); m_sCleanFormSet.insert("textarea"); m_sCleanFormSet.insert("marquee"); m_sCleanFormSet.insert("object"); m_sCleanFormSet.insert("select"); m_sCleanFormSet.insert("iframe"); m_sCleanFormSet.insert("style"); m_sCleanFormSet.insert("script"); tree<HTML::Node>::iterator itTagTreeBegin = m_TagTree.begin(); tree<HTML::Node>::iterator itTagTreeEnd = m_TagTree.end(); while ( itTagTreeBegin != itTagTreeEnd ) { //遍历标签树,标签节点且节点名称在m_sCleanFormSet中则把标签节点在标签树上删除 if ( itTagTreeBegin->isTag() ) { string sTagName = itTagTreeBegin->tagName(); if ( m_sCleanFormSet.find(sTagName) != m_sCleanFormSet.end() ) { tree<HTML::Node>::sibling_iterator sibTmp = itTagTreeBegin; sibTmp++; m_TagTree.erase( itTagTreeBegin ); itTagTreeBegin = sibTmp; } else { itTagTreeBegin++ ; } }//end if else { itTagTreeBegin++; } }//end while }
inline void insert(int key,int val){ int x = root; int k = 0 ; for(;;) { if(key == keys[x]) { mp.erase(mp.find(vals[x])); vals[x] = val; Splay(x,0); return; } int f = (key > keys[x]); if(ch[x][f] == 0 ) { NewNode(ch[x][f],key,val); pre[ch[x][f]] = x; Splay(ch[x][f],0); return; }else{ x = ch[x][f]; } } }
/** Move all the branches from 'from' to 'where' on the tree 'tr_where' */ void move_branch(const tree<AstNode>::iterator& where, const tree<AstNode>::iterator& from, tree<AstNode>& tr_where) { copy_branch(where, from, tr_where); tr_where.erase(from); }