tree_can_code.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 // canonical code specialization for trees
00021 
00022 #ifndef _TREE_CAN_CODE_
00023 #define _TREE_CAN_CODE_
00024 
00025 using namespace std;
00026 
00027 #include <string>
00028 #include <sstream>
00029 #include "generic_classes.h"
00030 #include "typedefs.h"
00031 
00038 template<typename PP, typename V_T, typename E_T, template <typename> class ALLOC>
00039 class canonical_code<TREE_PROP, V_T, E_T, ALLOC>
00040 {
00041 
00042  public:
00043 
00044   typedef int STORAGE_TYPE;
00045   typedef V_T INIT_TYPE;
00046   typedef eqint COMPARISON_FUNC;
00047 
00048   canonical_code() {}
00049 
00050   void backtrack() {
00051   }
00052 
00053   template<class PAT>
00054   void init(const INIT_TYPE& v, PAT* pattern) { 
00055     typename map<V_T, int>::iterator i;
00056     i = len1_pat_map.find(v);
00057 
00058     if(i != len1_pat_map.end())
00059       _can_code = i->second;
00060     else {
00061       len1_pat_map[v] = init_counter;
00062       _can_code = init_counter++;
00063     }
00064 
00065     pattern->update_rmpath(0);
00066   }
00067 
00068   void insert_vertex(const INIT_TYPE& v) {
00069   }
00070 
00071   void update_code() { 
00072     _can_code = id_generator--;
00073   }
00074 
00075 
00076   STORAGE_TYPE getCode() const {
00077     return _can_code;
00078   }
00079 
00080  private:
00081   STORAGE_TYPE _can_code;
00082   static int id_generator;
00083   static map<V_T, int> len1_pat_map;
00084   static int init_counter;
00085 
00086 };//end class canonical_code for tree
00087 
00088 template<class PP, typename V_T, typename E_T, template <typename> class ALLOC>
00089 int canonical_code<TREE_PROP, V_T, E_T, ALLOC >::id_generator = -1;
00090 
00091 template<class PP, typename V_T, typename E_T, template <typename> class ALLOC >
00092 int canonical_code<TREE_PROP, V_T, E_T, ALLOC >::init_counter = 1;
00093 
00094 template<class PP, typename V_T, typename E_T, template <typename> class ALLOC >
00095 map<V_T, int> canonical_code<TREE_PROP, V_T, E_T, ALLOC >::len1_pat_map;
00096 
00097 
00098 #endif

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