Generated on Sun Feb 17 15:24:24 2019 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  *  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 
00043 
00044   template<class I>
00045   unsigned int size(I& i);
00046 
00048   template<class I, class J>
00049   bool equal(I& i, J& j);
00050 
00052   template<class I, class J>
00053   bool subset(I& i, J& j);
00054 
00056   template<class I, class J>
00057   bool disjoint(I& i, J& j);
00058 
00060   enum CompareStatus {
00061     CS_SUBSET,   
00062     CS_DISJOINT, 
00063     CS_NONE      
00064   };
00065 
00067   template<class I, class J>
00068   CompareStatus compare(I& i, J& j);
00070 
00071 
00072   template<class I>
00073   inline unsigned int
00074   size(I& i) {
00075     unsigned int s = 0;
00076     while (i()) {
00077       s += i.width(); ++i;
00078     }
00079     return s;
00080   }
00081 
00082   template<class I, class J>
00083   forceinline bool
00084   equal(I& i, J& j) {
00085     // Are i and j equal?
00086     while (i() && j())
00087       if ((i.min() == j.min()) && (i.max() == j.max())) {
00088         ++i; ++j;
00089       } else {
00090         return false;
00091       }
00092     return !i() && !j();
00093   }
00094 
00095   template<class I, class J>
00096   forceinline bool
00097   subset(I& i, J& j) {
00098     // Is i subset of j?
00099     while (i() && j())
00100       if (j.max() < i.min()) {
00101         ++j;
00102       } else if ((i.min() >= j.min()) && (i.max() <= j.max())) {
00103         ++i;
00104       } else {
00105         return false;
00106       }
00107     return !i();
00108   }
00109 
00110   template<class I, class J>
00111   forceinline bool
00112   disjoint(I& i, J& j) {
00113     // Are i and j disjoint?
00114     while (i() && j())
00115       if (j.max() < i.min()) {
00116         ++j;
00117       } else if (i.max() < j.min()) {
00118         ++i;
00119       } else {
00120         return false;
00121       }
00122     return true;
00123   }
00124 
00125   template<class I, class J>
00126   forceinline CompareStatus
00127   compare(I& i, J& j) {
00128     bool subset = true;
00129     bool disjoint = true;
00130     while (i() && j()) {
00131       if (j.max() < i.min()) {
00132         ++j;
00133       } else if (i.max() < j.min()) {
00134         ++i; subset = false;
00135       } else if ((i.min() >= j.min()) && (i.max() <= j.max())) {
00136         ++i; disjoint = false;
00137       } else if (i.max() <= j.max()) {
00138         ++i; disjoint = false; subset = false;
00139       } else if (j.max() <= i.max()) {
00140         ++j; disjoint = false; subset = false;
00141       }
00142     }
00143     if (i())
00144       subset = false;
00145     if (subset)
00146       return CS_SUBSET;
00147     return disjoint ? CS_DISJOINT : CS_NONE;
00148   }
00149 
00150 }}}
00151 
00152 // STATISTICS: iter-any
00153