<
classTTreeNode,
classTCompFun>
62 bool TreeCompare(
constTTreeNode& tree1,
constTTreeNode& tree2, TCompFun func)
65 constTTreeNode* t1 = &tree1;
66 constTTreeNode* t2 = &tree2;
67 if(!func(t1->GetValue(), t2->GetValue()))
69 if(t1->IsLeaf() && t2->IsLeaf())
72 typedef typenameTTreeNode::TNodeList_CI CTreeNodeIterator;
74CTreeNodeIterator it1 = t1->SubNodeBegin();
75CTreeNodeIterator it1_end = t1->SubNodeEnd();
76CTreeNodeIterator it2 = t2->SubNodeBegin();
77CTreeNodeIterator it2_end = t2->SubNodeEnd();
79queue<CTreeNodeIterator> t1_queue;
80queue<CTreeNodeIterator> t2_queue;
85 while(it1 != it1_end) {
90 while(it2 != it2_end) {
96 if(children1 != children2)
100 while(!t1_queue.empty() && !t2_queue.empty()) {
103it1 = t1_queue.front();
105it2 = t2_queue.front();
112 if(!func(t1->GetValue(), t2->GetValue()))
117it1 = t1->SubNodeBegin();
118it1_end = t1->SubNodeEnd();
119 while(it1 != it1_end) {
120t1_queue.push(it1++);
126it2 = t2->SubNodeBegin();
127it2_end = t2->SubNodeEnd();
128 while(it2 != it2_end) {
129t2_queue.push(it2++);
133 if(children1 != children2)
140 if(t1_queue.empty() && t2_queue.empty())
155 template<
classTTreeNode,
classTFunc>
158 boolskip_self =
false)
160 constTTreeNode* node_ptr = &tree_node;
162node_ptr = node_ptr->GetParent();
164 for( ;node_ptr; node_ptr = node_ptr->GetParent()) {
174 template<
classTTreeNode,
classTTraceContainer>
204 template<
classTTreeNode,
classTTraceContainer>
216 template<
classTTreeNode>
219vector<const TTreeNode*>
trace;
221TTreeNode* local_root = &new_root_node;
222 ITERATE(
typenamevector<const TTreeNode*>, it,
trace) {
223TTreeNode* node =
const_cast<TTreeNode*
>(*it);
224TTreeNode* parent = node->GetParent();
226parent->DetachNode(node);
227 if(local_root != node)
228local_root->AddNode(node);
243 template<
classTTreeNode>
245 constTTreeNode& tree_node_b)
247 typedefvector<const TTreeNode*> TTraceVector;
249TTraceVector trace_a;
250TTraceVector trace_b;
257 constTTreeNode* node_candidate = 0;
264 constTTraceVector& ctr_a = trace_a;
265 constTTraceVector& ctr_b = trace_b;
267 typenameTTraceVector::const_reverse_iterator it_a = ctr_a.rbegin();
268 typenameTTraceVector::const_reverse_iterator it_b = ctr_b.rbegin();
270 typenameTTraceVector::const_reverse_iterator it_a_end = ctr_a.rend();
271 typenameTTraceVector::const_reverse_iterator it_b_end = ctr_b.rend();
273 for(;it_a != it_a_end || it_b != it_b_end; ++it_a, ++it_b) {
274 constTTreeNode* node_a = *it_a;
275 constTTreeNode* node_b = *it_b;
277 if(node_a != node_b) {
280node_candidate = node_a;
283 returnnode_candidate;
289 template<
classTTreeNode,
classTConverter>
306 const typenameTTreeNode::TValueType& v = tr.GetValue();
307 const string& node_str =
m_Conv(v);
311<<
"["<<
"0x"<<
hex<< &tr <<
"]=> 0x"<< tr.GetParent()
312<<
" ( "<< node_str <<
" ) "<< endl;
347 template<
classTTreeNode,
classTConverter>
349 constTTreeNode& tree_node,
351 boolprint_ptr =
false)
355TTreeNode* non_c_tr =
const_cast<TTreeNode*
>(&tree_node);
374 template<
classTPairTree,
classTValue>
376 constTValue& search_id)
378 constTPairTree* ptr = &tr;
381 constTValue& node_value = ptr->GetValue().value;
383 if(search_id == node_value) {
387 typenameTPairTree::TNodeList_CI it = ptr->SubNodeBegin();
388 typenameTPairTree::TNodeList_CI it_end = ptr->SubNodeEnd();
390 for(;it != it_end; ++it) {
391 constTPairTree* node = *it;
392 const typenameTPairTree::TValueType& node_pair = node->GetValue();
394 if(search_id == node_pair.id) {
400ptr = ptr->GetParent();
411 template<
classTPairTree,
classTPathList>
416 constTPairTree* ptr = &tr;
417 constTPairTree* pfnd = 0;
419 typenameTPathList::const_iterator last_it = node_path.end();
423 ITERATE(
typenameTPathList, sit, node_path) {
424 const typenameTPairTree::TKeyType& search_id = *sit;
425 boolsub_level_found =
false;
427 typenameTPairTree::TNodeList_CI it = ptr->SubNodeBegin();
428 typenameTPairTree::TNodeList_CI it_end = ptr->SubNodeEnd();
430 for(;it != it_end; ++it) {
431 constTPairTree* node = *it;
432 const typenameTPairTree::TValueType& node_pair = node->GetValue();
435 if(node_pair.id == search_id) {
436ptr = (TPairTree*) node;
437sub_level_found =
true;
440 if(node_pair.id == last_search_id) {
441pfnd = (TPairTree*) node;
442sub_level_found =
true;
450 if(!sub_level_found) {
463 template<
classTNodeListIt,
classTBackInsert>
465TNodeListIt node_list_last,
466TBackInsert back_ins)
468 for(;node_list_first != node_list_last; ++node_list_first)
470 unsigneduid = (unsigned)(*node_list_first)->GetValue().GetId();
481 template<
classTNodeList,
classTBackInsert>
484 typenameTNodeList::const_iterator it = node_list.begin();
485 typenameTNodeList::const_iterator it_end = node_list.end();
495 template<
classTTreeNode,
classTBackInsert>
506 if(delta_level >= 0) {
525 template<
classTNode,
classTBackInsert>
540 template<
classTNode,
classTBackInsert>
543TNode* node =
const_cast<TNode*
>(&tree_node);
555 template<
classTNode,
classTBackInsert>
558 typenameTNode::TNodeList_CI it = tree_node.SubNodeBegin();
559 typenameTNode::TNodeList_CI it_end = tree_node.SubNodeEnd();
561 for(;it != it_end; ++it) {
562 constTNode* node = *it;
563*back_ins = node->GetValue().GetId();
573 template<
classTTreeNode,
classTSet,
classTNodeList>
585 if(delta_level >= 0) {
586 unsigned id= node.GetValue().GetId();
608 template<
classTNode,
classTSet,
classTNodeList>
610 constTSet& node_set,
613TNode* node =
const_cast<TNode*
>(&tree_node);
626 template<
classTNode,
classTSet,
classTNodeList>
631TNodeList& dst_nlist)
638 ITERATE(
typenameTNodeList, it, src_nlist) {
641ancestor_set.clear();
645ancestor_set &= src_set;
646 unsigned cnt= ancestor_set.count();
650dst_nlist.push_back(snode);
664 template<
classTNode,
classTSet,
classTNodeList>
679TNodeList& dst_nlist,
680 constTSet* ignore_set = 0)
682 MinimalSet(src_nlist, dst_nlist, ignore_set);
690TNodeList& dst_nlist,
691 constTSet* ignore_set = 0)
704src_set, tmp_set, child_set, ignore_set);
709src_set, tmp_set, child_set, ignore_set);
718 unsigned id= snode->GetValue().GetId();
721 bool b= src_set[id];
729 ITERATE(
typenameTNodeList, it, src_nlist) {
731 unsigned id= snode->GetValue().GetId();
733 bool b= src_set[id];
735dst_nlist.push_back(snode);
743TNodeList& dst_nlist,
747 constTSet* ignore_set)
751 boolpromo_flag =
false;
753 ITERATE(
typenameTNodeList, it, nlist) {
756 unsigned id= snode->GetValue().GetId();
757TNode* parent = snode->GetParent();
760 bool b= src_set[id];
761 if(!
b|| (parent == 0))
764 unsignedparent_id = parent->GetValue().GetId();
773tmp_set -= *ignore_set;
776 if(tmp_set.none()) {
781src_set -= child_set;
783 boolparent_in = src_set[parent_id];
786src_set[parent_id] =
true;
792 if(&nlist != &dst_nlist) {
793dst_nlist.push_back(parent);
795tmp_nlist.push_back(parent);
805 ITERATE(
typenameTNodeList, it, tmp_nlist) {
807dst_nlist.push_back(snode);
815 template<
classTNode,
classTSet,
classTNodeList>
833 constTNodeList& src_nlist_b,
834 constTSet& mask_set,
841 unsigneddst_count = dst_set.count();
842 unsignedsrc_count = mask_set.count();
844 if(src_count != dst_count) {
852 constTSet& mask_set,
856 ITERATE(
typenameTNodeList, it, src_nlist) {
857 unsigned id= (*it)->GetValue().GetId();
858 boolexists = mask_set[id];
860exists = dst_set[id];
862dst_list.push_back(*it);
873 template<
classTNode,
classTSet,
classTNodeList>
878 constTNodeList& src_nlist_b,
879TNodeList& dst_nlist)
882this->
operator()(src_nlist_a, src_nlist_b, dst_nlist, tmp_set);
886 constTNodeList& src_nlist_b,
887TNodeList& dst_nlist,
901merge_func.
JoinNodeList(src_nlist_a, src_nlist_b, set_a,
908 template<
classTNode,
classTSet,
classTNodeList>
913 constTNodeList& src_nlist_b,
914TNodeList& dst_nlist)
917this->
operator()(src_nlist_a, src_nlist_b, dst_nlist, tmp_set);
921 constTNodeList& src_nlist_b,
922TNodeList& dst_nlist,
936merge_func.
JoinNodeList(src_nlist_a, src_nlist_b, set_a,
Utility to join to node lists according to a set of ids.
Functor to trace node pointers to root and create set of parents (TreeForEachParent)
Functor takes a single nodelist as an argument and tries to push that nodelist as high as it can.
Node list AND (set intersection)
Class-algorithm to compute Non Redundant Set.
Functor to trace node pointers to root (TreeForEachParent)
Tree print functor used as a tree traversal payload.
Functor to convert tree to a nodelist by the set pattern.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
void operator()(const TNodeList &src_nlist_a, const TNodeList &src_nlist_b, TNodeList &dst_nlist, TSet &dst_set)
void operator()(const TNodeList &src_nlist_a, const TNodeList &src_nlist_b, TNodeList &dst_nlist)
ETreeTraverseCode operator()(const TTreeNode &node, int delta_level=0)
void operator()(const TNodeList &src_nlist, TNodeList &dst_nlist)
CTreeIdToSetFunc(TBackInsert back_ins)
Fun TreeDepthFirstTraverse(TTreeNode &tree_node, Fun func)
Depth-first tree traversal algorithm.
TTraceContainer * m_Trace
ETreeTraverseCode
Tree traverse code returned by the traverse predicate function.
void operator()(const TNodeList &src_nlist_a, const TNodeList &src_nlist_b, TNodeList &dst_nlist, TSet &dst_set)
const TTreeNode * TreeFindCommonParent(const TTreeNode &tree_node_a, const TTreeNode &tree_node_b)
Check if two nodes have the same common root.
CTreeSet2NodeListFunc(const TSet &node_set, TNodeList *node_list)
bool TreeCompare(const TTreeNode &tree1, const TTreeNode &tree2, TCompFun func)
Compare two trees using comparison functor where order of children matters.
TFunc TreeForEachParent(const TTreeNode &tree_node, TFunc func, bool skip_self=false)
Visit every parent of the specified node.
CTreePrintFunc(CNcbiOstream &os, TConverter &conv, bool print_ptr)
void TreeMakeParentsSet(const TNode &tree_node, TBackInsert back_ins)
Traverses all ancestors and add their ids to a set.
void MinimalSet(const TNodeList &src_nlist, TNodeList &dst_nlist, const TSet *ignore_set=0)
void operator()(const TNodeList &src_nlist_a, const TNodeList &src_nlist_b, TNodeList &dst_nlist)
void operator()(const TNodeList &src_nlist, TNodeList &dst_nlist, const TSet *ignore_set=0)
Compute minimal set.
void MaskCopyNodes(const TNodeList &src_nlist, const TSet &mask_set, TNodeList &dst_list, TSet &dst_set)
Copy nodes from the source node list to destination if nodes are in the mask set and not yet in the d...
void TreeMakeSubNodesSet(const TNode &tree_node, TBackInsert back_ins)
Create set of all immediate sub-nodes (one level down from the root)
bool CheckNodeList(const TNodeList &nlist, TNodeList &dst_nlist, TSet &src_set, TSet &tmp_set, TSet &child_set, const TSet *ignore_set)
void TreeListToSet(TNodeListIt node_list_first, TNodeListIt node_list_last, TBackInsert back_ins)
Convert list of node pointers to set of ids Input set is represented by input forward iterators Outpu...
ETreeTraverseCode operator()(const TTreeNode &node, int delta_level=0)
const TPairTree * PairTreeTraceNode(const TPairTree &tr, const TPathList &node_path)
Algorithm to trace the pair tree and find specified leaf along the node path.
void TreeReRoot(TTreeNode &new_root_node)
Change tree root (tree rotation)
void TreeMakeSet(const TNode &tree_node, TBackInsert back_ins)
Create set of all sub-nodes (recursively)
void JoinNodeList(const TNodeList &src_nlist_a, const TNodeList &src_nlist_b, const TSet &mask_set, TNodeList &dst_list, TSet &dst_set)
Join two node lists.
void TreeSetToNodeList(const TNode &tree_node, const TSet &node_set, TNodeList &nlist)
Convert set of node ids to list of nodes.
void TreeTraceToRoot(const TTreeNode &tree_node, TTraceContainer &trace)
Trace from the specified node to to the tree root.
const TPairTree * PairTreeBackTraceNode(const TPairTree &tr, const TValue &search_id)
Algorithm to to search for a node with specified id.
void TreePrint(CNcbiOstream &os, const TTreeNode &tree_node, TConverter conv, bool print_ptr=false)
Tree printing (use for debugging purposes)
CTreeParentTraceFunc(TTraceContainer *trace)
ETreeTraverseCode operator()(const TTreeNode &tr, int delta)
void operator()(const TTreeNode &node)
@ eTreeTraverse
Keep traversal.
static void hex(unsigned char c)
double value_type
The numeric datatype used by the parser.
Int4 delta(size_t dimension_, const Int4 *score_)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4