00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef MEM_STORAGE_MANAGER_H_
00021 #define MEM_STORAGE_MANAGER_H_
00022
00023 #include<memory>
00024 #include <ext/hash_map>
00025 #include "pat_fam.h"
00026 #include "pat_support.h"
00027 #include "generic_classes.h"
00028 #include "helper_funs.h"
00029 #include "time_tracker.h"
00030
00031 using namespace std;
00032
00033
00034
00043 template<class PAT, template <typename> class ALLOC, class VAT >
00044 class storage_manager<PAT, VAT, ALLOC, memory_storage>
00045 {
00046
00047 typedef typename PAT::CC_STORAGE_TYPE C_ST;
00048 typedef typename PAT::CC_COMPARISON_FUNC C_CF;
00049
00050
00051 public:
00052
00053 typedef HASHNS::hash_map<C_ST, VAT*, HASHNS::hash<C_ST>, C_CF, ALLOC<pair<const C_ST, VAT*> > > CC_ST_TO_VATPTR;
00054 typedef typename CC_ST_TO_VATPTR::const_iterator CONST_IT;
00055 typedef typename CC_ST_TO_VATPTR::iterator IT;
00056 typedef pattern_support<typename PAT::MINE_PROPS> PAT_SUP;
00057
00058 storage_manager() {}
00059
00060 storage_manager(pat_fam<PAT>& freq_one_pats, vector<VAT*>& freq_one_vats) {
00061
00062 typename pat_fam<PAT>::CONST_IT cit = freq_one_pats.begin();
00063 int idx = 0;
00064
00065 while(cit != freq_one_pats.end()) {
00066 PAT* p = *cit;
00067
00068 _pat_to_vat.insert(make_pair(p->pat_id(), freq_one_vats[idx++]));
00069 cit++;
00070 }
00071 }
00072
00076 bool find(PAT* const& p) const {
00077 CONST_IT hmap_it;
00078 hmap_it=_pat_to_vat.find(p->pat_id());
00079
00080 return !(hmap_it==_pat_to_vat.end());
00081 }
00082
00086 VAT* get_vat(PAT* const& p) const {
00087
00088 CONST_IT hmap_it;
00089 hmap_it=_pat_to_vat.find(p->pat_id());
00090 if(hmap_it!=_pat_to_vat.end()) {
00091
00092 return hmap_it->second;
00093 }
00094 else {
00095 return 0;
00096 }
00097 }
00098
00102 void delete_vat(PAT* const& p) {
00103
00104 IT hmap_it;
00105 hmap_it=_pat_to_vat.find(p->pat_id());
00106 if(hmap_it!=_pat_to_vat.end()) {
00107 VAT* vat=hmap_it->second;
00108 if(vat)
00109 delete vat;
00110 else
00111 std::cout<<"storage_manager.delete_vat: vat is null"<<endl;
00112 _pat_to_vat.erase(hmap_it);
00113 }
00114 else {
00115 std::cout<<"storage_manager.delete_vat:vat not found for "<<p->pat_id()<<endl;
00116 }
00117 }
00118
00122 bool add_vat(PAT* const& p, VAT* v) {
00123 bool ret=(_pat_to_vat.insert(make_pair(p->pat_id(), v))).second;
00124
00125 return ret;
00126 }
00127
00131 VAT** intersect(PAT* const& p1, PAT* const& p2, PAT_SUP** cand_sups, PAT** cand_pats, bool is_l2) {
00132
00133
00134 VAT* v1, *v2;
00135
00136 CONST_IT hmap_it;
00137 hmap_it = _pat_to_vat.find(p1->pat_id());
00138 if(hmap_it!=_pat_to_vat.end()) {
00139
00140 v1 = hmap_it->second;
00141 }
00142 else {
00143 cout<< "storage_manager: vat not found for pattern = " << p1->pat_id() << endl;
00144 return 0;
00145 }
00146
00147 hmap_it = _pat_to_vat.find(p2->pat_id());
00148 if(hmap_it!=_pat_to_vat.end()) {
00149
00150 v2 = hmap_it->second;
00151 }
00152 else {
00153 cout<< "storage_manager: vat not found for pattern = " << p2->pat_id() << endl;
00154 return 0;
00155 }
00156
00157 VAT** ret = VAT::intersection(v1, v2, cand_sups, cand_pats, is_l2);
00158
00159 return ret;
00160 }
00161
00162 void print() const {
00163 CONST_IT hmap_it;
00164 for(hmap_it=_pat_to_vat.begin();hmap_it!=_pat_to_vat.end();hmap_it++)
00165 cout<<hmap_it->first<<"->"<<hmap_it->second<<endl;
00166 }
00167
00168 private:
00169
00170 CC_ST_TO_VATPTR _pat_to_vat;
00171 };
00172
00173 #endif