Generated on Mon Aug 25 11:35:37 2008 for Gecode by doxygen 1.5.6

tuple-set.icc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Mikael Lagerkvist <lagerkvist@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Mikael Lagerkvist, 2007
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-02-06 18:48:22 +0100 (Wed, 06 Feb 2008) $ by $Author: schulte $
00011  *     $Revision: 6102 $
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 {
00039 
00044   class GECODE_VTABLE_EXPORT TupleSet::TupleSetI
00045     : public SharedHandle::Object {
00046   public:
00048     int arity;
00050     int size;
00052     Tuple** tuples;
00054     Tuple* tuple_data;
00056     int* data;
00058     int excess;
00060     int min, max;
00062     int domsize;
00064     Tuple** last;
00066     Tuple* nullptr;
00067 
00069     template <class T>
00070     void add(T t);
00072     GECODE_INT_EXPORT void finalize(void);
00074     GECODE_INT_EXPORT void resize(void);
00076     bool finalized(void) const;
00078     TupleSetI(void);
00080     GECODE_INT_EXPORT virtual ~TupleSetI(void);
00082     GECODE_INT_EXPORT virtual SharedHandle::Object* copy(void) const;
00083   };
00084 
00085   forceinline bool
00086   TupleSet::TupleSetI::finalized(void) const { 
00087     assert((excess == -1 && domsize >= 0) ||
00088            (excess != -1 && domsize == -1)); 
00089     return excess == -1; 
00090   }
00091 
00092   forceinline
00093   TupleSet::TupleSetI::TupleSetI(void) 
00094     : arity(-1),
00095       size(0),
00096       tuples(NULL),
00097       tuple_data(NULL),
00098       data(NULL),
00099       excess(0),
00100       min(Int::Limits::max),
00101       max(Int::Limits::min),
00102       domsize(-1),
00103       last(NULL),
00104       nullptr(NULL)
00105   {}
00106 
00107 
00108   template <class T>
00109   void
00110   TupleSet::TupleSetI::add(T t){
00111     assert(arity  != -1); // Arity has been set
00112     assert(excess != -1); // Tuples may still be added
00113     if (excess == 0) resize();
00114     assert(excess >= 0);
00115     --excess;
00116     int end = size*arity;
00117     for (int i = arity; i--; ) {
00118       data[end+i] = t[i];
00119       if (t[i] < min) min = t[i];
00120       if (t[i] > max) max = t[i];
00121     }
00122     ++size;
00123   }
00124 
00125   forceinline
00126   TupleSet::TupleSet(void) {
00127   }
00128 
00129   forceinline
00130   TupleSet::TupleSet(const TupleSet& ts) 
00131     : SharedHandle(ts) {}
00132 
00133   forceinline TupleSet::TupleSetI*
00134   TupleSet::implementation(void) {
00135     TupleSetI* imp = static_cast<TupleSetI*>(object());
00136     assert(imp);
00137     return imp;
00138   }
00139 
00140   inline void
00141   TupleSet::add(const IntArgs& tuple) {
00142     TupleSetI* imp = static_cast<TupleSetI*>(object());
00143     if (imp == NULL) {
00144       imp = new TupleSetI;
00145       object(imp);
00146     }
00147     assert(imp->arity == -1 ||
00148            imp->arity == tuple.size());
00149     imp->arity = tuple.size();
00150     imp->add(tuple);
00151   }
00152 
00153   forceinline void
00154   TupleSet::finalize(void) {
00155     TupleSetI* imp = static_cast<TupleSetI*>(object());
00156     assert(imp);
00157     if (!imp->finalized()) {
00158       imp->finalize();
00159     }
00160   }
00161 
00162   forceinline bool
00163   TupleSet::finalized(void) const {
00164     TupleSetI* imp = static_cast<TupleSetI*>(object());
00165     assert(imp);
00166     return imp->finalized();
00167   }
00168 
00169   forceinline int
00170   TupleSet::arity(void) const {
00171     TupleSetI* imp = static_cast<TupleSetI*>(object());
00172     assert(imp);
00173     assert(imp->arity != -1);
00174     return imp->arity;
00175   }
00176   forceinline int
00177   TupleSet::tuples(void) const {
00178     TupleSetI* imp = static_cast<TupleSetI*>(object());
00179     assert(imp);
00180     assert(imp->finalized());
00181     return imp->size-1;
00182   }
00183   forceinline TupleSet::Tuple
00184   TupleSet::operator[](int i) const {
00185     TupleSetI* imp = static_cast<TupleSetI*>(object());
00186     assert(imp);
00187     assert(imp->finalized());
00188     return imp->data + i*imp->arity;
00189   }
00190   forceinline int
00191   TupleSet::min(void) const {
00192     TupleSetI* imp = static_cast<TupleSetI*>(object());
00193     assert(imp);
00194     assert(imp->finalized());
00195     return imp->min;
00196   }
00197   forceinline int
00198   TupleSet::max(void) const {
00199     TupleSetI* imp = static_cast<TupleSetI*>(object());
00200     assert(imp);
00201     assert(imp->finalized());
00202     return imp->max;
00203   }
00204 }
00205 
00206 // STATISTICS: int-prop
00207