00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _TREE_OPERATORS_H
00021 #define _TREE_OPERATORS_H
00022
00023 #include "typedefs.h"
00024
00025 class Fk_Fk;
00026
00032 template<class PP, class MP, class PAT_ST, template<typename, typename, typename, template <typename> class > class CC,
00033 template <typename> class ALLOC >
00034 int compute_pos(const TREE_PATTERN* pat) {
00035 typename TREE_PATTERN::CONST_EIT_PAIR ep=pat->in_edges(pat->rmost_vid());
00036 if(ep.first==ep.second) {
00037
00038 return -1;
00039 }
00040
00041 return ep.first->first;
00042 }
00043
00047 template<typename PATTERN>
00048 class compare_pos
00049 {
00050 public:
00051 bool operator()(const PATTERN* p1, const PATTERN* p2) const {
00052 return compute_pos(p1)>compute_pos(p2);
00053 }
00054 };
00055
00056 template<class PP, class MP, class PAT_ST, template<typename, typename, typename, template <typename> class > class CC,
00057 template <typename> class ALLOC >
00058 ostream& operator<< (ostream& ostr, const TREE_PATTERN* p) {
00059
00060 stack<typename TREE_PATTERN::CONST_EIT_PAIR> st;
00061
00062 typename TREE_PATTERN::CONST_IT it;
00063 for(it=p->begin(); it!=p->end(); it++) {
00064 if(it == p->begin()) {
00065 ostr << (*it).v;
00066 st.push(p->out_edges((*it).id));
00067
00068 } else {
00069 bool btrack = false;
00070 while(st.top().first == st.top().second) {
00071 st.pop();
00072 ostr << " <-- ";
00073 btrack = true;
00074 st.top().first++;
00075 }
00076
00077 if(!btrack) {
00078 ostr << " --- " << (*it).v;
00079 } else {
00080 ostr << (*it).v;
00081 }
00082
00083 st.push(p->out_edges((*it).id));
00084 }
00085 }
00086 ostr <<" -- " <<p->_pat_sup;
00087
00088 return ostr;
00089 }
00090
00091 #endif