00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00027 #ifndef _SPLIT_DELTA_H_
00028 #define _SPLIT_DELTA_H_
00029
00030 #include <api_delta.h>
00031 #include <bound_delta.h>
00032
00033 class split_undelta : public undelta_base
00034 {
00035 private:
00036 work_node::transaction_number se;
00037
00038 public:
00039 split_undelta(const work_node::transaction_number& _se) : se(_se) {}
00040
00041 split_undelta(const split_undelta& _su) : se(_su.se)
00042 {
00043 #if DEBUG_DELTA
00044 std::cerr << "Called split_undelta copy constructor" << std::endl;
00045 #endif
00046 }
00047
00048 virtual ~split_undelta() {}
00049
00050 split_undelta* new_copy() const { return new split_undelta(*this); }
00051 void destroy_copy(split_undelta* __d) { delete __d; }
00052
00053 bool unapply(work_node& x) const
00054 {
00055 std::map<work_node::transaction_number,std::list<std::vector<delta> > >::iterator _f;
00056 _f = x.proposed_splits.find(se);
00057 if(_f != x.proposed_splits.end())
00058 {
00059 x.proposed_splits.erase(_f);
00060 return true;
00061 }
00062 else
00063 return false;
00064 }
00065 };
00066
00067 class split_delta : public delta_base
00068 {
00069 public:
00070 std::list<std::vector<delta> > splits;
00071
00072
00073
00074
00075
00076
00077 split_delta() : delta_base("split"), splits() {}
00078
00079
00080
00081
00082
00083 split_delta(unsigned int _node_num, const interval& _l, const interval& _u)
00084 : delta_base("split"), splits()
00085 {
00086 splits.push_back(std::vector<delta>(1,
00087 delta(bound_delta(_node_num, _l))));
00088 splits.push_back(std::vector<delta>(1,
00089 delta(bound_delta(_node_num, _u))));
00090 }
00091
00092 split_delta(unsigned int _node_num, const std::vector<interval>& _m)
00093 : delta_base("split"), splits()
00094 {
00095 for(std::vector<interval>::const_iterator __l = _m.begin();
00096 __l != _m.end(); ++__l)
00097 {
00098 splits.push_back(std::vector<delta>(1,
00099 delta(bound_delta(_node_num, *__l))));
00100 }
00101 }
00102
00103 split_delta(const std::vector<unsigned int>& _i,
00104 const std::vector<interval>& _l, const std::vector<interval>& _u)
00105 : delta_base("split"), splits()
00106 {
00107 splits.push_back(std::vector<delta>(1,delta(bound_delta(_i, _l))));
00108 splits.push_back(std::vector<delta>(1,delta(bound_delta(_i, _u))));
00109 }
00110
00111 split_delta(const std::list<std::vector<delta> >& __dl)
00112 : delta_base("split"), splits(__dl)
00113 {}
00114
00115 ~split_delta() {}
00116
00117 split_delta(const split_delta& __s) : delta_base(__s), splits(__s.splits) {}
00118
00119 split_delta* new_copy() const { return new split_delta(*this); }
00120 void destroy_copy(split_delta* __d) { delete __d; }
00121
00122 void add_delta(const delta& __d)
00123 {
00124 splits.push_back(std::vector<delta>(1,__d));
00125 }
00126
00127 void add_deltas(const std::vector<delta>& __d)
00128 {
00129 splits.push_back(__d);
00130 }
00131
00132 void add_split(unsigned int _nnum, interval _l, interval _u)
00133 {
00134 splits.push_back(std::vector<delta>(1,delta(bound_delta(_nnum, _l))));
00135 splits.push_back(std::vector<delta>(1,delta(bound_delta(_nnum, _u))));
00136 }
00137
00138 void add_split(const std::vector<unsigned int>& _i,
00139 const std::vector<interval>& _l,
00140 const std::vector<interval>& _u)
00141 {
00142 splits.push_back(std::vector<delta>(1,delta(bound_delta(_i, _l))));
00143 splits.push_back(std::vector<delta>(1,delta(bound_delta(_i, _u))));
00144 }
00145
00146 bool apply(work_node& x, undelta_base*& _u) const
00147 {
00148 work_node::transaction_number se(x.get_transaction_number());
00149 x.proposed_splits.insert(std::make_pair(se,splits));
00150 _u = (undelta_base*) new split_undelta(se);
00151 return true;
00152 }
00153 };
00154
00155 #endif