Generated on Thu Apr 11 13:59:13 2019 for Gecode by doxygen 1.6.3

ranges-append.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2004
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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    * Binary Append
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    * Nary Append
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       //Skip empty iterators:
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 // STATISTICS: iter-any
00218