Generated on Thu Mar 22 10:39:42 2012 for Gecode by doxygen 1.6.3

ranges-operations.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  *  Last modified:
00010  *     $Date: 2010-07-28 17:35:33 +0200 (Wed, 28 Jul 2010) $ by $Author: schulte $
00011  *     $Revision: 11294 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 namespace Gecode { namespace Iter { namespace Ranges {
00039 
00047 
00048   template<class I>
00049   unsigned int size(I& i);
00050 
00052   template<class I, class J>
00053   bool equal(I& i, J& j);
00054 
00056   template<class I, class J>
00057   bool subset(I& i, J& j);
00058 
00060   template<class I, class J>
00061   bool disjoint(I& i, J& j);
00062 
00064   enum CompareStatus {
00065     CS_SUBSET,   
00066     CS_DISJOINT, 
00067     CS_NONE      
00068   };
00069 
00071   template<class I, class J>
00072   CompareStatus compare(I& i, J& j);
00074 
00075 
00076   template<class I>
00077   inline unsigned int
00078   size(I& i) {
00079     unsigned int s = 0;
00080     while (i()) {
00081       s += i.width(); ++i;
00082     }
00083     return s;
00084   }
00085 
00086   template<class I, class J>
00087   forceinline bool
00088   equal(I& i, J& j) {
00089     // Are i and j equal?
00090     while (i() && j())
00091       if ((i.min() == j.min()) && (i.max() == j.max())) {
00092         ++i; ++j;
00093       } else {
00094         return false;
00095       }
00096     return !i() && !j();
00097   }
00098 
00099   template<class I, class J>
00100   forceinline bool
00101   subset(I& i, J& j) {
00102     // Is i subset of j?
00103     while (i() && j())
00104       if (j.max() < i.min()) {
00105         ++j;
00106       } else if ((i.min() >= j.min()) && (i.max() <= j.max())) {
00107         ++i;
00108       } else {
00109         return false;
00110       }
00111     return !i();
00112   }
00113 
00114   template<class I, class J>
00115   forceinline bool
00116   disjoint(I& i, J& j) {
00117     // Are i and j disjoint?
00118     while (i() && j())
00119       if (j.max() < i.min()) {
00120         ++j;
00121       } else if (i.max() < j.min()) {
00122         ++i;
00123       } else {
00124         return false;
00125       }
00126     return true;
00127   }
00128 
00129   template<class I, class J>
00130   forceinline CompareStatus
00131   compare(I& i, J& j) {
00132     bool subset = true;
00133     bool disjoint = true;
00134     while (i() && j()) {
00135       if (j.max() < i.min()) {
00136         ++j;
00137       } else if (i.max() < j.min()) {
00138         ++i; subset = false;
00139       } else if ((i.min() >= j.min()) && (i.max() <= j.max())) {
00140         ++i; disjoint = false;
00141       } else if (i.max() <= j.max()) {
00142         ++i; disjoint = false; subset = false;
00143       } else if (j.max() <= i.max()) {
00144         ++j; disjoint = false; subset = false;
00145       }
00146     }
00147     if (i())
00148       subset = false;
00149     if (subset)
00150       return CS_SUBSET;
00151     return disjoint ? CS_DISJOINT : CS_NONE;
00152   }
00153 
00154 }}}
00155 
00156 // STATISTICS: iter-any
00157