tree_operators.h

00001 /*
00002  *  Copyright (C) 2005 M.J. Zaki <zaki@cs.rpi.edu> Rensselaer Polytechnic Institute
00003  *  Written by parimi@cs.rpi.edu
00004  *  Updated by chaojv@cs.rpi.edu, alhasan@cs.rpi.edu, salems@cs.rpi.edu
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
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     // single node tree
00038     return -1;
00039   }
00040 
00041   return ep.first->first;
00042 }//end compute_pos()
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 << "  <--  ";  // backtracking 
00073         btrack = true;
00074         st.top().first++;
00075       }
00076       
00077       if(!btrack) {
00078         ostr << "  ---  " << (*it).v;  // forward edge
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

Generated on Wed Jul 26 14:01:08 2006 for DMTL by  doxygen 1.4.7