ranges-append.icc
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 namespace Gecode { namespace Iter { namespace Ranges {
00023
00034 template <class I, class J>
00035 class Append : public MinMax {
00036 protected:
00038 I i;
00040 J j;
00041 public:
00043
00044
00045 Append(void);
00047 Append(I& i, J& j);
00049 void init(I& i, J& j);
00051
00053
00054
00055 void operator++(void);
00057 };
00058
00059
00070 template <class I>
00071 class NaryAppend : public MinMax {
00072 protected:
00074 I* r;
00076 unsigned int n;
00078 unsigned int active;
00079 public:
00081
00082
00083 NaryAppend(void);
00085 NaryAppend(I* i, unsigned int n);
00087 void init(I* i, unsigned int n);
00089
00091
00092
00093 void operator++(void);
00095 };
00096
00097
00098
00099
00100
00101
00102
00103 template <class I, class J>
00104 inline void
00105 Append<I,J>::operator++(void) {
00106 if (i()) {
00107 mi = i.min(); ma = i.max();
00108 ++i;
00109 if (!i() && j() && (j.min() == ma+1)) {
00110 ma = j.max();
00111 ++j;
00112 }
00113 } else if (j()) {
00114 mi = j.min(); ma = j.max();
00115 ++j;
00116 } else {
00117 finish();
00118 }
00119 }
00120
00121
00122 template <class I, class J>
00123 forceinline
00124 Append<I,J>::Append(void) {}
00125
00126 template <class I, class J>
00127 forceinline
00128 Append<I,J>::Append(I& i0, J& j0)
00129 : i(i0), j(j0) {
00130 if (i() || j())
00131 operator++();
00132 else
00133 finish();
00134 }
00135
00136 template <class I, class J>
00137 forceinline void
00138 Append<I,J>::init(I& i0, J& j0) {
00139 i = i0; j = j0;
00140 if (i() || j())
00141 operator++();
00142 else
00143 finish();
00144 }
00145
00146
00147
00148
00149
00150
00151
00152 template <class I>
00153 inline void
00154 NaryAppend<I>::operator++(void) {
00155 mi = r[active].min();
00156 ma = r[active].max();
00157 ++r[active];
00158 while (!r[active]()) {
00159
00160 do {
00161 active++;
00162 if (active >= n) {
00163 finish(); return;
00164 }
00165 } while (!r[active]());
00166 if (r[active].min() == ma+1){
00167 ma = r[active].max();
00168 ++r[active];
00169 } else {
00170 return;
00171 }
00172 }
00173 }
00174
00175 template <class I>
00176 forceinline
00177 NaryAppend<I>::NaryAppend(void) {}
00178
00179 template <class I>
00180 inline
00181 NaryAppend<I>::NaryAppend(I* r0, unsigned int n0)
00182 : r(r0), n(n0), active(0) {
00183 while (active < n && !r[active]())
00184 active++;
00185 if (active < n){
00186 operator++();
00187 } else {
00188 finish();
00189 }
00190 }
00191
00192 template <class I>
00193 inline void
00194 NaryAppend<I>::init(I* r0, unsigned int n0) {
00195 r = r0; n = n0; active = 0;
00196 while (active < n && !r[active]())
00197 active++;
00198 if (active < n){
00199 operator++();
00200 } else {
00201 finish();
00202 }
00203 }
00204
00205 }}}
00206
00207
00208