tuple-set.icc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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);
00112 assert(excess != -1);
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
00207