Generated on Wed Nov 1 15:04:41 2006 for Gecode by doxygen 1.4.5

ranges-minus.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Christian Schulte, 2004
00007  *
00008  *  Last modified:
00009  *     $Date: 2006-08-04 16:05:50 +0200 (Fri, 04 Aug 2006) $ by $Author: schulte $
00010  *     $Revision: 3515 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 #include "gecode/support/shared-array.hh"
00023 
00024 namespace Gecode { namespace Iter { namespace Ranges {
00025 
00039   template <class I>
00040   class Minus  {
00041   private:
00043     class Range {
00044     public:
00045       int min; int max;
00046     };
00048     Support::SharedArray<Range> r;
00050     int c;
00052     int n;
00053   public:
00055 
00056 
00057     Minus(void);
00059     Minus(I& i);
00061     void init(I& i);
00063 
00065 
00066 
00067     bool operator()(void) const;
00069     void operator++(void);
00071 
00073 
00074 
00075     int min(void) const;
00077     int max(void) const;
00079     unsigned int width(void) const;
00081   };
00082 
00083 
00084   template <class I>
00085   forceinline
00086   Minus<I>::Minus(void)
00087     : r(8) {}
00088 
00089   template <class I>
00090   inline void
00091   Minus<I>::init(I& i) {
00092     int j = 0;
00093     while (i()) {
00094       r.ensure(j);
00095       r[j].min = -i.max(); r[j].max = -i.min();
00096       ++j; ++i;
00097     }
00098     n = j;
00099     c = n-1;
00100   }
00101 
00102   template <class I>
00103   inline
00104   Minus<I>::Minus(I& i) : r(8) {
00105     init(i);
00106   }
00107 
00108   template <class I>
00109   forceinline void
00110   Minus<I>::operator++(void) {
00111     c--;
00112   }
00113   template <class I>
00114   forceinline bool
00115   Minus<I>::operator()(void) const {
00116     return c >= 0;
00117   }
00118 
00119   template <class I>
00120   forceinline int
00121   Minus<I>::min(void) const {
00122     return r[c].min;
00123   }
00124   template <class I>
00125   forceinline int
00126   Minus<I>::max(void) const {
00127     return r[c].max;
00128   }
00129   template <class I>
00130   forceinline unsigned int
00131   Minus<I>::width(void) const {
00132     return r[c].max-r[c].min+1;
00133   }
00134 
00135 }}}
00136 
00137 // STATISTICS: iter-any
00138