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 namespace Gecode { namespace Iter { namespace Ranges {
00035
00045 template<class I, class J>
00046 class Append : public MinMax {
00047 protected:
00049 I i;
00051 J j;
00052 public:
00054
00055
00056 Append(void);
00058 Append(I& i, J& j);
00060 void init(I& i, J& j);
00062
00064
00065
00066 void operator ++(void);
00068 };
00069
00070
00080 template<class I>
00081 class NaryAppend : public MinMax {
00082 protected:
00084 I* r;
00086 int n;
00088 int active;
00089 public:
00091
00092
00093 NaryAppend(void);
00095 NaryAppend(I* i, int n);
00097 void init(I* i, int n);
00099
00101
00102
00103 void operator ++(void);
00105 };
00106
00107
00108
00109
00110
00111
00112
00113 template<class I, class J>
00114 inline void
00115 Append<I,J>::operator ++(void) {
00116 if (i()) {
00117 mi = i.min(); ma = i.max();
00118 ++i;
00119 if (!i() && j() && (j.min() == ma+1)) {
00120 ma = j.max();
00121 ++j;
00122 }
00123 } else if (j()) {
00124 mi = j.min(); ma = j.max();
00125 ++j;
00126 } else {
00127 finish();
00128 }
00129 }
00130
00131
00132 template<class I, class J>
00133 forceinline
00134 Append<I,J>::Append(void) {}
00135
00136 template<class I, class J>
00137 forceinline
00138 Append<I,J>::Append(I& i0, J& j0)
00139 : i(i0), j(j0) {
00140 if (i() || j())
00141 operator ++();
00142 else
00143 finish();
00144 }
00145
00146 template<class I, class J>
00147 forceinline void
00148 Append<I,J>::init(I& i0, J& j0) {
00149 i = i0; j = j0;
00150 if (i() || j())
00151 operator ++();
00152 else
00153 finish();
00154 }
00155
00156
00157
00158
00159
00160
00161
00162 template<class I>
00163 inline void
00164 NaryAppend<I>::operator ++(void) {
00165 mi = r[active].min();
00166 ma = r[active].max();
00167 ++r[active];
00168 while (!r[active]()) {
00169
00170 do {
00171 active++;
00172 if (active >= n) {
00173 finish(); return;
00174 }
00175 } while (!r[active]());
00176 if (r[active].min() == ma+1){
00177 ma = r[active].max();
00178 ++r[active];
00179 } else {
00180 return;
00181 }
00182 }
00183 }
00184
00185 template<class I>
00186 forceinline
00187 NaryAppend<I>::NaryAppend(void) {}
00188
00189 template<class I>
00190 inline
00191 NaryAppend<I>::NaryAppend(I* r0, int n0)
00192 : r(r0), n(n0), active(0) {
00193 while (active < n && !r[active]())
00194 active++;
00195 if (active < n){
00196 operator ++();
00197 } else {
00198 finish();
00199 }
00200 }
00201
00202 template<class I>
00203 inline void
00204 NaryAppend<I>::init(I* r0, int n0) {
00205 r = r0; n = n0; active = 0;
00206 while (active < n && !r[active]())
00207 active++;
00208 if (active < n){
00209 operator ++();
00210 } else {
00211 finish();
00212 }
00213 }
00214
00215 }}}
00216
00217
00218