iset_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 #ifndef _ISET_CAN_CODE_
00021 #define _ISET_CAN_CODE_
00022 
00023 #include<sstream>
00024 #include<string>
00025 #include<map>
00026 
00027 #include "helper_funs.h"
00028 #include "typedefs.h"
00029 #include "generic_classes.h"
00030 
00031 using namespace std;
00032 
00033 
00040 template<class PP, typename vertex_t, typename edge_t, 
00041          template <typename> class ALLOC >
00042 class canonical_code<ISET_PROP, vertex_t, edge_t, ALLOC > 
00043 {
00044  public:
00045   
00046   typedef int STORAGE_TYPE;
00047   typedef vertex_t INIT_TYPE;
00048   typedef eqint COMPARISON_FUNC;
00049   
00050   canonical_code() {}
00051   
00060   template<class PAT>
00061   void init(INIT_TYPE v, PAT* pat) {
00062     
00063     typename map<vertex_t, int>::iterator i;
00064     i = len1_pat_map.find(v);
00065     
00066     if(i != len1_pat_map.end())
00067       _c_code = i->second;
00068     else {
00069       len1_pat_map[v] = init_counter;
00070       _c_code = init_counter++;
00071     }
00072   }
00073 
00078   inline
00079   void insert_vertex(const vertex_t& v) {
00080     _c_code = id_generator--; 
00081   }
00082   
00086   STORAGE_TYPE getCode() const {
00087     return _c_code;
00088   }
00089   
00090   void update_code() {}
00091   
00092   
00093  private:
00094   STORAGE_TYPE _c_code;
00095   static int id_generator;
00096   static map<vertex_t, int> len1_pat_map;
00097   static int init_counter;
00098 };
00099 
00100 // Setting it to -1 since for level-1 the _c_code should be 
00101 // same as the vertex id. Beyond level-1 the id gets assigned 
00102 // from the id_generator.
00103 template<class PP, typename v, typename e, template <typename> class ALLOC >
00104 int canonical_code<ISET_PROP, v, e, ALLOC>::id_generator = -1;
00105 
00106 template<class PP, typename v, typename e, template <typename> class ALLOC >
00107 int canonical_code<ISET_PROP, v, e, ALLOC>::init_counter = 1;
00108 
00109 template<class PP, typename v, typename e, template <typename> class ALLOC >
00110 map<v, int> canonical_code<ISET_PROP, v, e, ALLOC >::len1_pat_map;
00111 
00112 #endif

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