mem_storage_manager.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 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 // time_tracker tt_tot_inter;
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   // typedef typename VAT::VAT_ALLOC ALLOC;
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   }//end find()
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       //vat found
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; //reclaim memory for vat
00110       else
00111         std::cout<<"storage_manager.delete_vat: vat is null"<<endl;
00112       _pat_to_vat.erase(hmap_it); //erases pat-vat mapping from hashmap
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     // Get the vats.
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       //vat found
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       //vat found
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   }// end print()
00167   
00168 private:
00169     
00170   CC_ST_TO_VATPTR _pat_to_vat; // A pattern to vat map
00171 };
00172 
00173 #endif

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