00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef FILE_STORAGE_MANAGER_H
00022 #define FILE_STORAGE_MANAGER_H
00023
00024 #include<string>
00025 #include<memory>
00026 #include <ext/hash_map>
00027 #include "pat_fam.h"
00028 #include "pat_support.h"
00029 #include "generic_classes.h"
00030 #include "helper_funs.h"
00031 #include "time_tracker.h"
00032 #include "file_cache_manager.h"
00033
00034 using namespace std;
00035
00036 #define FILENAME "__DMTL_file_cache.dat"
00037
00044 template<class PAT, template <typename> class ALLOC, class VAT >
00045 class storage_manager<PAT, VAT, ALLOC, file_storage > {
00046
00047 typedef typename PAT::CC_STORAGE_TYPE C_ST;
00048 typedef typename PAT::CC_COMPARISON_FUNC C_CF;
00049
00050 public:
00051
00052 typedef int key_type;
00053
00054 typedef VAT data_type;
00055 typedef VAT VATT;
00056
00057
00058
00059
00060 typedef cache_manager<key_type, data_type> cache_type;
00061
00062 typedef typename cache_type::size_type size_type;
00063 typedef pattern_support<typename PAT::MINE_PROPS> PAT_SUP;
00064
00065 storage_manager(){}
00066
00067 storage_manager(typename cache_type::size_type C=1,const char * filename=FILENAME){
00068 Cache = new cache_type(C, filename);
00069 manager_count++;
00070 }
00071
00072
00073 ~storage_manager(){
00074 if(manager_count==1){
00075 delete Cache;
00076 }
00077 manager_count--;
00078 }
00079
00082 size_type mem_entries() const {
00083 return Cache->mem_entries();
00084 }
00085
00088 size_type file_entries() const {
00089 return Cache->file_entries();
00090 }
00091
00092 void print_stats() const{
00093 Cache->print_stats();
00094 }
00095
00096 bool find(PAT* const& p) const{
00097 return Cache->find_vat(p->pat_id());
00098 }
00099
00100
00101 void delete_vat(PAT* const& p){
00102 Cache->delete_vat(p->pat_id());
00103 }
00104
00105 void lock_vat(PAT* const& p) {
00106 Cache->lock_vat(p->pat_id());
00107 }
00108
00109 void unlock_vat(PAT* const& p) {
00110 Cache->unlock_vat(p->pat_id());
00111 }
00112
00113
00114 VAT* get_vat(PAT* const& p) const {
00115 VAT *value=Cache->get_vat_point(p->pat_id());
00116 return value;
00117 }
00118
00119
00120 VAT* get_vat(const key_type & id) const{
00121 VAT *value=Cache->get_vat_point_levelone(id);
00122 return value;
00123 }
00124
00128 VAT** intersect(PAT* const& p1, PAT* const& p2, PAT_SUP ** cand_sups,PAT ** cand_pats, bool is_l2) {
00129
00130 VAT* v1, *v2;
00131 v1 = Cache->get_vat_point(p1->pat_id());
00132 static int p1old=0;
00133 int p1new= p1->pat_id();
00134 if(p1new!=p1old){
00135 Cache->lock_vat(p1new);
00136 Cache->unlock_vat(p1old);
00137 p1old=p1new;
00138 }
00139
00140 v2 = Cache->get_vat_point(p2->pat_id());
00141
00142 if(v1 == 0 || v2 == 0) {
00143 cout<< "file_storage_manager: vat not found for pattern = " << p1->pat_id() << endl;
00144 return NULL;
00145 }
00146
00147 return VAT::intersection(v1, v2, cand_sups, cand_pats,is_l2);
00148 }
00149
00150
00151 bool add_vat(const PAT* const& p, VAT* v){
00152 bool ret;
00153 ret=Cache->insert(p->pat_id(),v);
00154 return ret;
00155 }
00156
00157
00158 void write_file(const key_type & id,VAT* v){
00159 Cache->write_file(id,*v);
00160 }
00161
00162
00163 bool my_add_vat(const key_type & id, VAT* v){
00164 bool ret;
00165 ret=Cache->insert_levelone(id,v);
00166
00167 return ret;
00168 }
00169
00174 void initialize_vat(std::map<int, int> & mapcount) {
00175 std::map<int, int>::iterator it;
00176 for (it = mapcount.begin(); it != mapcount.end(); ++it) {
00177 VAT* ivat=new VAT();
00178 ivat->resize(it->second);
00179 my_add_vat(it->first,ivat);
00180 }
00181 }
00182
00183 private:
00184 cache_type* Cache;
00185
00186 static int manager_count;
00187 };
00188
00189 template<class PAT, template <typename> class ALLOC, class VAT >
00190 int storage_manager<PAT, VAT, ALLOC, file_storage >::manager_count=0;
00191
00192 #endif