ranges-minus.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
00052 template<class I>
00053 class Minus {
00054 private:
00056 IsRangeIter<I> _checkI;
00057 private:
00059 class Range {
00060 public:
00061 int min; int max;
00062 };
00064 SharedArray<Range> r;
00066 int c;
00067 public:
00069
00070
00071 Minus(void);
00073 Minus(I& i);
00075 void init(I& i);
00077
00079
00080
00081 bool operator ()(void) const;
00083 void operator ++(void);
00085
00087
00088
00089 int min(void) const;
00091 int max(void) const;
00093 unsigned int width(void) const;
00095 };
00096
00097
00098 template<class I>
00099 forceinline
00100 Minus<I>::Minus(void) {}
00101
00102 template<class I>
00103 inline void
00104 Minus<I>::init(I& i) {
00105 Support::DynamicArray<Range,Heap> d(heap);
00106 int n=0;
00107 while (i()) {
00108 d[n].min = -i.max(); d[n].max = -i.min();
00109 ++n; ++i;
00110 }
00111 r.init(n);
00112 for (int j=n; j--; )
00113 r[j]=d[j];
00114 c = n-1;
00115 }
00116
00117 template<class I>
00118 inline
00119 Minus<I>::Minus(I& i) {
00120 init(i);
00121 }
00122
00123 template<class I>
00124 forceinline void
00125 Minus<I>::operator ++(void) {
00126 c--;
00127 }
00128 template<class I>
00129 forceinline bool
00130 Minus<I>::operator ()(void) const {
00131 return c >= 0;
00132 }
00133
00134 template<class I>
00135 forceinline int
00136 Minus<I>::min(void) const {
00137 return r[c].min;
00138 }
00139 template<class I>
00140 forceinline int
00141 Minus<I>::max(void) const {
00142 return r[c].max;
00143 }
00144 template<class I>
00145 forceinline unsigned int
00146 Minus<I>::width(void) const {
00147 return static_cast<unsigned int>(r[c].max-r[c].min+1);
00148 }
00149
00150 }}}
00151
00152
00153