00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _MSET_VAT_H_
00021 #define _MSET_VAT_H_
00022
00023 #include <iterator>
00024 #include "pattern.h"
00025 #include "pat_support.h"
00026 #include "generic_classes.h"
00027 #include "typedefs.h"
00028
00029 template<class PP, class MP, template <typename> class ALLOC, template <typename P, typename> class ST >
00030 ostream& operator<< (ostream& , const vat<PP, MP, ALLOC, ST >&);
00031
00032 template<class PP, class MP, template <typename> class ALLOC, template <typename P, typename> class ST >
00033 istream& operator>> (istream& , vat<PP, MP, ALLOC, ST >&);
00034
00035
00044 template<class PP, class MP, template <typename> class ALLOC, template <typename, typename> class ST >
00045 class vat<MSET_PROP, V_Fkk_MINE_PROP, ALLOC, ST >
00046 {
00047 public:
00048 typedef pattern_support<V_Fkk_MINE_PROP> PAT_SUP;
00049 typedef vat<MSET_PROP, V_Fkk_MINE_PROP, ALLOC, ST > VAT;
00050
00051 typedef ST<pair<int, int>, ALLOC<pair<int, int> > > IDLIST_T;
00052 typedef typename IDLIST_T::const_iterator CONST_IT;
00053 typedef typename IDLIST_T::iterator IT;
00054
00055
00056 void* operator new(size_t size) {
00057 ALLOC<VAT> a;
00058 return a.allocate(size);
00059 }
00060
00061 void operator delete(void *p, size_t size) {
00062 if (p) {
00063 ALLOC<VAT> a;
00064 a.deallocate(static_cast<VAT*> (p), size);
00065 }
00066 }
00067
00068 vat() {}
00069
00070 IT begin() {
00071 return _idlist.begin();
00072 }
00073
00074 CONST_IT begin() const {
00075 return _idlist.begin();
00076 }
00077
00078 IT end() {
00079 return _idlist.end();
00080 }
00081
00082 CONST_IT end() const {
00083 return _idlist.end();
00084 }
00085
00086 bool empty() const {
00087 return _idlist.empty;
00088 }
00089
00090 int size() {
00091 return _idlist.size();
00092 }
00093
00094 void make_empty() {
00095 _idlist.clear();
00096 }
00097
00099 void push_back(const pair<int, int>& val) {
00100 _idlist.push_back(val);
00101 }
00102
00104 pair<int, int>& operator[](int n) {
00105 return *(begin()+n);
00106 }
00107
00109 void resize(int x) {
00110 _idlist.resize(x);
00111 }
00112
00113
00114 void clear() {
00115 _idlist.clear();
00116 }
00117
00118
00129 template<class PAT>
00130 static VAT** intersection(const VAT* const& vat_i, const VAT* const& vat_j, PAT_SUP** cand_sups, PAT**, bool& is_l2) {
00131
00132 VAT** cand_vats = new VAT*[1];
00133 cand_vats[0] = new VAT();
00134
00135
00136
00137 if(cand_sups[0] == 0) {
00138 delete cand_vats[0];
00139 delete[] cand_vats;
00140
00141 cerr << "mset_vat: No candidates VATs to be generated." << endl;
00142 return NULL;
00143 }
00144
00145 CONST_IT it_i=vat_i->begin(), it_j=vat_j->begin();
00146
00147 while(it_i!=vat_i->end() && it_j!=vat_j->end()) {
00148 if((*it_i).first < (*it_j).first) {
00149 it_i++;
00150 continue;
00151 }
00152
00153 if((*it_j).first < (*it_i).first) {
00154 it_j++;
00155 continue;
00156 }
00157
00158 if(vat_i == vat_j) {
00159 if((*it_i).second > 1)
00160 cand_vats[0]->push_back(make_pair((*it_i).first, (*it_i).second-1));
00161 } else {
00162 cand_vats[0]->push_back(make_pair((*it_i).first, (*it_j).second));
00163 }
00164
00165 it_i++;
00166 it_j++;
00167 }
00168
00169
00170 cand_sups[0]->set_sup(make_pair(cand_vats[0]->size(), cand_vats[0]->size()));
00171
00172 return cand_vats;
00173 }
00174
00179 unsigned long size() const {
00180 return _idlist.size();
00181 }
00182
00186 vat(const VAT &orig) {
00187 *this= orig;
00188 }
00189
00190 ~vat(){
00191 _idlist.clear();
00192 }
00193
00197 const VAT &operator=(const VAT &right) {
00198 if ( &right != this ) {
00199 _idlist=right._idlist;
00200 }
00201 else
00202 cout << "Attempted assignment of a Vat to itself\n";
00203
00204 return *this;
00205 }
00206
00207
00208 unsigned long int byte_size() const {
00209
00210 return _idlist.size()* sizeof(int);
00211 }
00212
00241 friend ostream& operator<< <>(ostream& , const VAT&);
00242
00243 friend istream& operator>> <>(istream& , VAT&);
00244
00245 private:
00246 IDLIST_T _idlist;
00247
00248 };
00249
00250
00251 template<class T, class MP, template <typename> class ALLOC, template <typename P, typename> class ST >
00252 ostream& operator<<(ostream& output, vat<T, MP, ALLOC, ST> const& orig) {
00253 std::ostream_iterator<int> out(output, " ");
00254 std::copy(orig.begin(), orig.end(), out);
00255 output <<'\n';
00256 return output;
00257 }
00258
00259 template<class T, class MP, template <typename> class ALLOC, template <typename P, typename> class ST >
00260 istream& operator>>(istream& input, vat<T, MP, ALLOC, ST >& orig) {
00261 const unsigned int MAXLINE=20000;
00262 char line[MAXLINE];
00263 input.getline(line,MAXLINE);
00264 stringstream s(line);
00265 std::istream_iterator<int> in(s);
00266 std::istream_iterator<int> eof;
00267
00268 orig._idlist.clear();
00269 std::copy (in,eof, std::back_inserter(orig._idlist));
00270 return input;
00271 }
00272
00273 #endif