00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _ISET_VAT_H_
00021 #define _ISET_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<ISET_PROP, V_Fkk_MINE_PROP, ALLOC, ST >
00046 {
00047 public:
00048 typedef pattern_support<V_Fkk_MINE_PROP> PAT_SUP;
00049 typedef vat<ISET_PROP, V_Fkk_MINE_PROP, ALLOC, ST > VAT;
00050
00051 typedef ST<int, ALLOC<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> va;
00058 return va.allocate(size);
00059 }
00060
00061 void operator delete(void *p, size_t size) {
00062 if (p) {
00063 ALLOC<VAT> va;
00064 va.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 int& val) {
00100 _idlist.push_back(val);
00101 }
00102
00104 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 << "iset_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 < *it_j) {
00149 it_i++;
00150 continue;
00151 }
00152
00153 if(*it_j < *it_i) {
00154 it_j++;
00155 continue;
00156 }
00157
00158
00159 cand_vats[0]->push_back(*it_i);
00160 it_i++;
00161 it_j++;
00162 }
00163
00164
00165 cand_sups[0]->set_sup(make_pair(cand_vats[0]->size(), cand_vats[0]->size()));
00166
00167 return cand_vats;
00168 }
00169
00174 unsigned long size() const {
00175 return _idlist.size();
00176 }
00177
00181 vat(const VAT &orig) {
00182 *this= orig;
00183 }
00184
00185 ~vat(){
00186 _idlist.clear();
00187 }
00188
00192 const VAT &operator=(const VAT &right) {
00193 if ( &right != this ) {
00194 _idlist=right._idlist;
00195 }
00196 else
00197 cout << "Attempted assignment of a Vat to itself\n";
00198
00199 return *this;
00200 }
00201
00202
00203 unsigned long int byte_size() const {
00204
00205 return _idlist.size()* sizeof(int);
00206 }
00207
00208
00209 void write_file(ostream & output_file) const {
00210
00211 ostringstream output;
00212 CONST_IT iter;
00213 iter =_idlist.begin();
00214 for (;iter!=_idlist.end();iter++){
00215
00216 output.write( reinterpret_cast<const char *>( & (*iter) ), sizeof(int));
00217 }
00218 output_file.write(output.str().c_str(), output.str().size());
00219 }
00220
00221
00222 void read_file (istream & input, unsigned long int size) {
00223
00224 int ITSZ=sizeof(int);
00225 int buf_size=size/ITSZ;
00226 int *buf = new int[buf_size];
00227 input.read((char *)buf, size);
00228 int current=0;
00229 _idlist.clear();
00230 while( current< buf_size){
00231 _idlist.push_back(buf[current++]);
00232 }
00233 delete [] buf;
00234 }
00235
00236 friend ostream& operator<< <>(ostream& , const VAT&);
00237
00238 friend istream& operator>> <>(istream& , VAT&);
00239
00240 private:
00241 IDLIST_T _idlist;
00242
00243 };
00244
00245
00246 template<class T, class MP, template <typename> class ALLOC, template <typename P, typename> class ST >
00247 ostream& operator<<(ostream& output, vat<T, MP, ALLOC, ST> const& orig) {
00248 std::ostream_iterator<int> out(output, " ");
00249 std::copy(orig.begin(), orig.end(), out);
00250 output <<'\n';
00251 return output;
00252 }
00253
00254 template<class T, class MP, template <typename> class ALLOC, template <typename P, typename> class ST >
00255 istream& operator>>(istream& input, vat<T, MP, ALLOC, ST >& orig) {
00256 const unsigned int MAXLINE=20000;
00257 char line[MAXLINE];
00258 input.getline(line,MAXLINE);
00259 stringstream s(line);
00260 std::istream_iterator<int> in(s);
00261 std::istream_iterator<int> eof;
00262
00263 orig._idlist.clear();
00264 std::copy (in,eof, std::back_inserter(orig._idlist));
00265 return input;
00266 }
00267
00268 #endif