ranges-cache.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: 2005-07-29 21:55:06 +0200 (Fri, 29 Jul 2005) $ by $Author: schulte $ 00010 * $Revision: 2085 $ 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 "support/shared-array.hh" 00023 00024 namespace Gecode { namespace Iter { namespace Ranges { 00025 00036 template <class I> 00037 class Cache { 00038 protected: 00040 class Range { 00041 public: 00042 int min; int max; 00043 }; 00045 Support::SharedArray<Range> r; 00047 int c; 00049 int n; 00050 public: 00052 00053 00054 Cache(void); 00056 Cache(I& i); 00058 void init(I& i); 00060 00062 00063 00064 bool operator()(void) const; 00066 void operator++(void); 00068 void reset(void); 00070 00072 00073 00074 int min(void) const; 00076 int max(void) const; 00078 unsigned int width(void) const; 00080 }; 00081 00082 00083 template <class I> 00084 forceinline 00085 Cache<I>::Cache(void) 00086 : r(8) {} 00087 00088 template <class I> 00089 inline void 00090 Cache<I>::init(I& i) { 00091 int j = 0; 00092 while (i()) { 00093 r.ensure(j); 00094 r[j].min = i.min(); r[j].max = i.max(); 00095 ++j; ++i; 00096 } 00097 c = 0; 00098 n = j; 00099 } 00100 00101 template <class I> 00102 inline 00103 Cache<I>::Cache(I& i) : r(8) { 00104 init(i); 00105 } 00106 00107 template <class I> 00108 forceinline void 00109 Cache<I>::operator++(void) { 00110 c++; 00111 } 00112 template <class I> 00113 forceinline bool 00114 Cache<I>::operator()(void) const { 00115 return c < n; 00116 } 00117 00118 template <class I> 00119 forceinline void 00120 Cache<I>::reset(void) { 00121 c = 0; 00122 } 00123 00124 template <class I> 00125 forceinline int 00126 Cache<I>::min(void) const { 00127 return r[c].min; 00128 } 00129 template <class I> 00130 forceinline int 00131 Cache<I>::max(void) const { 00132 return r[c].max; 00133 } 00134 template <class I> 00135 forceinline unsigned int 00136 Cache<I>::width(void) const { 00137 return r[c].max-r[c].min+1; 00138 } 00139 00140 }}} 00141 00142 // STATISTICS: iter-any 00143