ranges-inter.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
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <algorithm>
00039
00040 namespace Gecode { namespace Iter { namespace Ranges {
00041
00047 template <class I, class J>
00048 class Inter : public MinMax {
00049 protected:
00051 I i;
00053 J j;
00054 public:
00056
00057
00058 Inter(void);
00060 Inter(I& i, J& j);
00062 void init(I& i, J& j);
00064
00066
00067
00068 void operator++(void);
00070 };
00071
00072
00078 template <class I>
00079 class NaryInter : public MinMax {
00080 protected:
00082 I* is;
00084 int n;
00085 public:
00087
00088
00089 NaryInter(void);
00091 NaryInter(I* i, int n);
00093 void init(I* i, int n);
00095
00097
00098
00099 void operator++(void);
00101 };
00102
00103
00104
00105
00106
00107
00108
00109 template <class I, class J>
00110 inline void
00111 Inter<I,J>::operator++(void) {
00112 if (!i() || !j()) goto done;
00113 do {
00114 while (i() && (i.max() < j.min())) ++i;
00115 if (!i()) goto done;
00116 while (j() && (j.max() < i.min())) ++j;
00117 if (!j()) goto done;
00118 } while (i.max() < j.min());
00119
00120 ma = std::min(i.max(),j.max());
00121 mi = std::max(i.min(),j.min());
00122 if (i.max() < j.max()) ++i; else ++j;
00123 return;
00124 done:
00125 finish();
00126 }
00127
00128 template <class I, class J>
00129 forceinline
00130 Inter<I,J>::Inter(void) {}
00131
00132 template <class I, class J>
00133 forceinline
00134 Inter<I,J>::Inter(I& i0, J& j0)
00135 : i(i0), j(j0) {
00136 operator++();
00137 }
00138
00139 template <class I, class J>
00140 forceinline void
00141 Inter<I,J>::init(I& i0, J& j0) {
00142 i = i0; j = j0;
00143 operator++();
00144 }
00145
00146
00147
00148
00149
00150
00151
00152 template <class I>
00153 inline void
00154 NaryInter<I>::operator++(void) {
00155
00156
00157 mi = ma+2;
00158 ma = is[0].max();
00159
00160 restart:
00161 for (int i = n; i--;) {
00162
00163 while (is[i]() && (is[i].max() < mi))
00164 ++is[i];
00165 if (!is[i]())
00166 goto done;
00167
00168 if (is[i].min() > ma) {
00169 mi=is[i].min();
00170 ma=is[i].max();
00171 goto restart;
00172 }
00173
00174 if (mi < is[i].min())
00175 mi = is[i].min();
00176 if (ma > is[i].max()) {
00177 ma = is[i].max();
00178 }
00179 }
00180 return;
00181 done:
00182 finish();
00183 }
00184
00185 template <class I>
00186 forceinline
00187 NaryInter<I>::NaryInter(void) {}
00188
00189 template <class I>
00190 inline
00191 NaryInter<I>::NaryInter(I* is0, int n0)
00192 : is(is0), n(n0) {
00193 if (!is[0]()) {
00194 finish();
00195 } else {
00196 ma=is[0].min()-2;
00197 operator++();
00198 }
00199 }
00200
00201 template <class I>
00202 inline void
00203 NaryInter<I>::init(I* is0, int n0) {
00204 is = is0; n = n0;
00205 if (!is[0]()) {
00206 finish();
00207 } else {
00208 ma=is[0].min()-2;
00209 operator++();
00210 }
00211 }
00212
00213 }}}
00214
00215
00216