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 }
void onMonitoringEnabled(const tree<core::FileInfo>& files) { enqueFiles(files.begin_leaf(), files.end_leaf()); }