00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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