ranges-append.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 namespace Gecode { namespace Iter { namespace Ranges {
00039
00049 template<class I, class J>
00050 class Append : public MinMax {
00051 protected:
00053 I i;
00055 J j;
00056 public:
00058
00059
00060 Append(void);
00062 Append(I& i, J& j);
00064 void init(I& i, J& j);
00066
00068
00069
00070 void operator ++(void);
00072 };
00073
00074
00084 template<class I>
00085 class NaryAppend : public MinMax {
00086 protected:
00088 I* r;
00090 int n;
00092 int active;
00093 public:
00095
00096
00097 NaryAppend(void);
00099 NaryAppend(I* i, int n);
00101 void init(I* i, int n);
00103
00105
00106
00107 void operator ++(void);
00109 };
00110
00111
00112
00113
00114
00115
00116
00117 template<class I, class J>
00118 inline void
00119 Append<I,J>::operator ++(void) {
00120 if (i()) {
00121 mi = i.min(); ma = i.max();
00122 ++i;
00123 if (!i() && j() && (j.min() == ma+1)) {
00124 ma = j.max();
00125 ++j;
00126 }
00127 } else if (j()) {
00128 mi = j.min(); ma = j.max();
00129 ++j;
00130 } else {
00131 finish();
00132 }
00133 }
00134
00135
00136 template<class I, class J>
00137 forceinline
00138 Append<I,J>::Append(void) {}
00139
00140 template<class I, class J>
00141 forceinline
00142 Append<I,J>::Append(I& i0, J& j0)
00143 : i(i0), j(j0) {
00144 if (i() || j())
00145 operator ++();
00146 else
00147 finish();
00148 }
00149
00150 template<class I, class J>
00151 forceinline void
00152 Append<I,J>::init(I& i0, J& j0) {
00153 i = i0; j = j0;
00154 if (i() || j())
00155 operator ++();
00156 else
00157 finish();
00158 }
00159
00160
00161
00162
00163
00164
00165
00166 template<class I>
00167 inline void
00168 NaryAppend<I>::operator ++(void) {
00169 mi = r[active].min();
00170 ma = r[active].max();
00171 ++r[active];
00172 while (!r[active]()) {
00173
00174 do {
00175 active++;
00176 if (active >= n) {
00177 finish(); return;
00178 }
00179 } while (!r[active]());
00180 if (r[active].min() == ma+1){
00181 ma = r[active].max();
00182 ++r[active];
00183 } else {
00184 return;
00185 }
00186 }
00187 }
00188
00189 template<class I>
00190 forceinline
00191 NaryAppend<I>::NaryAppend(void) {}
00192
00193 template<class I>
00194 inline
00195 NaryAppend<I>::NaryAppend(I* r0, int n0)
00196 : r(r0), n(n0), active(0) {
00197 while (active < n && !r[active]())
00198 active++;
00199 if (active < n){
00200 operator ++();
00201 } else {
00202 finish();
00203 }
00204 }
00205
00206 template<class I>
00207 inline void
00208 NaryAppend<I>::init(I* r0, int n0) {
00209 r = r0; n = n0; active = 0;
00210 while (active < n && !r[active]())
00211 active++;
00212 if (active < n){
00213 operator ++();
00214 } else {
00215 finish();
00216 }
00217 }
00218
00219 }}}
00220
00221
00222