00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _SEQ_INSTANCE_H_
00024 #define _SEQ_INSTANCE_H_
00025
00026 #include "typedefs.h"
00031 template <class MP>
00032 class seq_instance{};
00033
00034 template <class MP>
00035 ostream& operator<< (ostream& ostr, const seq_instance<V_Fkk_EMB_MINE_PROP>& rhs);
00036
00041 template <class MP>
00042 class seq_instance<V_Fkk_EMB_MINE_PROP>
00043 {
00044
00045 public:
00046
00047 seq_instance(): ts(-1) {}
00048
00049 seq_instance(const int timestamp, const int position): ts(timestamp) {}
00051 seq_instance(const int timestamp): ts(timestamp) {}
00053 int get_ts() const {return ts;}
00054
00064 template<template<typename, typename > class ST, template <typename> class ALLOC>
00065 static void seq_join_seq(const ST<seq_instance, ALLOC<seq_instance> >& i1, const ST<seq_instance, ALLOC<seq_instance> >& i2,
00066 ST<seq_instance, ALLOC<seq_instance> >& seqi_inst,
00067 ST<seq_instance, ALLOC<seq_instance> >& seqj_inst,
00068 bool& seqi_ind, bool& seqj_ind,
00069 bool& seqi_emb, bool& seqj_emb,
00070 const bool self_join_only)
00071 {
00072 typedef ST<seq_instance, ALLOC<seq_instance> > INSTANCES;
00073 typedef typename INSTANCES::const_iterator CONST_INST_IT;
00074 CONST_INST_IT it1, it2, it3;
00075
00076
00077 it1 = i1.begin();
00078 it2 = i2.end()-1;
00079 if (it1->ts < it2->ts){
00080 for(it1=i1.begin(), it2=i2.begin(); it1 != i1.end() && it2 != i2.end();) {
00081
00082 if (it1->ts < it2->ts){
00083
00084 for (it3 = it2; it3 != i2.end(); ++it3){
00085 seqi_inst.push_back(seq_instance(it3->ts));
00086 }
00087 seqi_emb = true;
00088 break;
00089 }
00090 else ++it2;
00091 }
00092 }
00093
00094
00095
00096 if(!self_join_only) {
00097 it1 = i1.end()-1;
00098 it2 = i2.begin();
00099 if (it2->ts < it1->ts){
00100 for(it1=i1.begin(), it2=i2.begin(); it1 != i1.end() && it2 != i2.end();) {
00101
00102 if (it2->ts < it1->ts){
00103
00104 for (it3 = it1; it3 != i1.end(); ++it3){
00105 seqj_inst.push_back(seq_instance(it3->ts));
00106 }
00107 seqj_emb = true;
00108 break;
00109 }
00110 else ++it1;
00111 }
00112 }
00113 }
00114
00115 }
00116
00117 friend ostream& operator<< <>(ostream& ostr, const seq_instance& rhs);
00118 private:
00119 int ts;
00120 };
00121
00122 template<class MP>
00123 ostream& operator<< (ostream& ostr, const seq_instance<V_Fkk_EMB_MINE_PROP>& rhs){
00124 ostr << "[ " << rhs.ts << " ] ";
00125 return ostr;
00126 }
00127
00128 template <class MP>
00129 ostream& operator<< (ostream& ostr, const seq_instance<V_Fkk_IND_MINE_PROP>& rhs);
00130
00135 template <class MP>
00136 class seq_instance<V_Fkk_IND_MINE_PROP>
00137 {
00138
00139 public:
00140
00141 seq_instance(): pos(-1), induced(false) {}
00142
00143 seq_instance(const int timestamp, const int position): pos(position), induced(true) {}
00145 seq_instance(const int position, const bool ind): pos(position), induced(ind) {}
00157 template<template<typename, typename > class ST, template <typename> class ALLOC>
00158 static void seq_join_seq(const ST<seq_instance, ALLOC<seq_instance> >& i1, const ST<seq_instance, ALLOC<seq_instance> >& i2,
00159 ST<seq_instance, ALLOC<seq_instance> >& seqi_inst,
00160 ST<seq_instance, ALLOC<seq_instance> >& seqj_inst,
00161 bool& seqi_ind, bool& seqj_ind,
00162 bool& seqi_emb, bool& seqj_emb,
00163 const bool self_join_only, const bool skip0=false)
00164 {
00165 typedef ST<seq_instance, ALLOC<seq_instance> > INSTANCES;
00166 typedef typename INSTANCES::const_iterator CONST_INST_IT;
00167 CONST_INST_IT it1, it2;
00168
00169 if (!skip0){
00170 bool seen_valid_occurrence = false;
00171
00172 for(it1=i1.begin(), it2=i2.begin(); it1 != i1.end() && it2 != i2.end();) {
00173
00174 if (it1->pos < it2->pos){
00175 seen_valid_occurrence = true;
00176 if (it1->is_induced() && it2->pos - it1->pos == 1){
00177 seqi_inst.push_back(seq_instance(it2->pos, true));
00178 seqi_ind = true;
00179 ++it2;
00180 }
00181 ++it1;
00182 }
00183 else{
00184 if (seen_valid_occurrence){
00185 seqi_inst.push_back(seq_instance(it2->pos, false));
00186 seqi_emb=true;
00187 }
00188 ++it2;
00189 }
00190 }
00191
00192 for (; it2 != i2.end(); ++it2){
00193 if (seen_valid_occurrence){
00194 seqi_inst.push_back(seq_instance(it2->pos, false));
00195 seqi_emb=true;
00196 }
00197 }
00198 }
00199
00200
00201 if(!self_join_only) {
00202 bool seen_valid_occurrence = false;
00203
00204 for(it1=i1.begin(), it2=i2.begin(); it1 != i1.end() && it2 != i2.end();) {
00205
00206 if (it2->pos < it1->pos){
00207 seen_valid_occurrence = true;
00208 if (it2->is_induced() && it1->pos - it2->pos == 1){
00209 seqj_inst.push_back(seq_instance(it1->pos, true));
00210 seqj_ind = true;
00211 ++it1;
00212 }
00213 ++it2;
00214 }
00215 else{
00216 if (seen_valid_occurrence){
00217 seqj_inst.push_back(seq_instance(it1->pos, false));
00218 seqj_emb=true;
00219 }
00220 ++it1;
00221 }
00222 }
00223
00224 for (; it1 != i1.end(); ++it1){
00225 if (seen_valid_occurrence){
00226 seqj_inst.push_back(seq_instance(it1->pos, false));
00227 seqj_emb=true;
00228 }
00229 }
00230 }
00231
00232 }
00233
00234 friend ostream& operator<< <>(ostream& ostr, const seq_instance& rhs);
00235 int get_pos() const {return pos;}
00236
00237 bool get_induced() const {
00238 return induced;
00239 }
00240
00241 private:
00242 int pos;
00243 bool induced;
00244 bool is_induced() const{
00245 return induced;
00246 }
00247 };
00248
00249 template <class MP>
00250 ostream& operator<< (ostream& ostr, const seq_instance<V_Fkk_IND_MINE_PROP>& rhs){
00251 ostr << "[ " << rhs.pos << ", " << rhs.induced << " ] ";
00252 return ostr;
00253 }
00254
00255
00256 #endif
00257