mset_vat.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 _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; // Definition of a itemset VAT.
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   //clear the vector
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]; // This memory is reclaimed in count() routine of count_support.h file
00133     cand_vats[0] = new VAT();      // This memory is reclaimed in count() routine of count_support.h file, only if the 
00134     // corresponding pattern is NOT frequent, otherwise, Storage Manager get a hold of this
00135     // VAT.
00136     
00137     if(cand_sups[0] == 0) { // No pattern_support class associated to return support value, ERROR
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) {  // Intersecting the same pattern.
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     }//end while
00168     
00169     // setting the support value that will be checked in the count method of count_support class.
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 ) {         // avoid self assignment
00199       _idlist=right._idlist;
00200     }
00201     else
00202       cout << "Attempted assignment of a Vat to itself\n";
00203     
00204     return *this;   // enables cascaded assignments
00205   }
00206   
00207   // Return Vat length
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;   // enables cascading
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;   // enables cascading
00271 }
00272 
00273 #endif

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