seq_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 _SEQ_CAN_CODE_H_
00021 #define _SEQ_CAN_CODE_H_
00022 
00023 #include<sstream>
00024 #include<string>
00025 #include<limits>
00026 #include "generic_classes.h"
00027 
00028 using namespace std;
00029 
00030 
00037 // template<class PP, typename V_T, typename E_T, template<typename> class ALLOC=std::allocator >
00038 template<class PP, typename V_T, typename E_T, template<typename> class ALLOC >
00039 class canonical_code<SEQ_PROP, V_T, E_T, ALLOC >
00040 {
00041  public:
00042   
00043   typedef int STORAGE_TYPE;
00044   typedef V_T INIT_TYPE;
00045   typedef eqint COMPARISON_FUNC;
00046   
00047   canonical_code() {}
00048   
00054   template<typename PAT>
00055     void init(V_T v, PAT*) {
00056     typename map<V_T, int>::iterator i;
00057     i = len1_pat_map.find(v);
00058     
00059     if(i != len1_pat_map.end())
00060       _can_code = i->second;
00061     else {
00062       len1_pat_map[v] = init_counter;
00063       _can_code = init_counter++;
00064     }
00065   }
00066   
00070   void insert_vertex(const V_T& v) {
00071     _can_code = id_generator--; 
00072     if(_can_code == INT_MIN) {
00073       cout << "Range of int values exhausted while assigning canonical code." << endl;
00074       cout << "Please report this error to the developers." << endl;
00075     }
00076   }
00077   
00078   
00079   void update_code() {}
00080   
00084   STORAGE_TYPE getCode() const {
00085     return _can_code;
00086   }
00087   
00088  private:
00089 
00090   STORAGE_TYPE _can_code;
00091   static int id_generator;
00092   static map<V_T, int> len1_pat_map;
00093   static int init_counter;
00094 };
00095 
00096 template<class PP, typename v, typename e, template <typename> class ALLOC >
00097          int canonical_code<SEQ_PROP, v, e, ALLOC>::id_generator = -1;
00098 
00099 template<class PP, typename v, typename e, template <typename> class ALLOC >
00100          int canonical_code<SEQ_PROP, v, e, ALLOC >::init_counter = 1;
00101 
00102 template<class PP, typename v, typename e, template <typename> class ALLOC >
00103          map<v, int> canonical_code<SEQ_PROP, v, e, ALLOC >::len1_pat_map;
00104 
00105 #endif

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