27#include "core/tb2types.hpp"
31#include <boost/version.hpp>
32#if (BOOST_VERSION >= 105600)
33#include <boost/type_index.hpp>
55template <
class T,
class V>
64 StoreStack(
const StoreStack& s);
65 StoreStack& operator=(
const StoreStack& s);
68 StoreStack(
int powbckmemory = STORE_SIZE)
70 if (pow(2., powbckmemory) >= SIZE_MAX) {
71 cerr <<
"command-line initial memory size parameter " << powbckmemory <<
" power of two too large!" << endl;
74 indexMax = (ptrdiff_t)pow(2., powbckmemory);
75 pointers =
new T*[indexMax];
76 content =
new V[indexMax];
79 if (ToulBar2::verbose > 0) {
80 cout <<
"c " << indexMax * (
sizeof(V) +
sizeof(T*)) <<
" Bytes allocated for "
82#
if (BOOST_VERSION >= 105600)
83 << boost::typeindex::type_id<T>().pretty_name()
100 T** newpointers =
new T*[indexMax * 2];
101 V* newcontent =
new V[indexMax * 2];
102 if (!newpointers || !newcontent) {
105#if (BOOST_VERSION >= 105600)
106 << boost::typeindex::type_id<T>().pretty_name()
111 <<
" stack out of memory!" << endl;
114 std::copy(pointers, pointers + indexMax, newpointers);
115 std::copy(content, content + indexMax, newcontent);
119 pointers = newpointers;
120 content = newcontent;
122 if (ToulBar2::verbose >= 0) {
123 cout <<
"c " << indexMax * (
sizeof(V) +
sizeof(T*)) <<
" Bytes allocated for "
125#
if (BOOST_VERSION >= 105600)
126 << boost::typeindex::type_id<T>().pretty_name()
131 <<
" stack." << endl;
135 void store(T* x, V y)
139 if (index >= indexMax)
150 if (index >= indexMax)
160 if (index >= indexMax)
162 pointers[index] = (T*)(intptr_t)base;
170 void restore(Value** adr, Value* val, ptrdiff_t x)
176 void restore(Cost** adr, Cost* val, ptrdiff_t x)
182 void restore(BigInteger** adr, BigInteger* val, ptrdiff_t x)
187 void restore(BTList<Q>** l, DLink<Q>** elt, ptrdiff_t& x);
197 restore(pointers, content, x);
201 base = (ptrdiff_t)pointers[y];
224 StoreBasic(
const StoreBasic& elt)
229 static void store() { mystore.store(); };
230 static void restore() { mystore.restore(); };
232 StoreBasic& operator=(
const StoreBasic& elt)
234 if (&elt !=
this && v != elt.v) {
241 StoreBasic& operator=(
const T vv)
249 StoreBasic& operator+=(
const T vv)
257 StoreBasic& operator-=(
const T vv)
266 static StoreStack<T, T> mystore;
270StoreStack<T, T> StoreBasic<T>::mystore(STORE_SIZE);
272typedef StoreBasic<Value> StoreValue;
273typedef StoreValue StoreInt;
274typedef StoreBasic<Cost> StoreCost;
275typedef StoreBasic<BigInteger> StoreBigInteger;
276typedef StoreCost StoreLong;
283 virtual ~Store() = 0;
287 static StoreStack<BTList<Value>, DLink<Value>*> storeDomain;
288 static StoreStack<BTList<ConstraintLink>, DLink<ConstraintLink>*> storeConstraint;
289 static StoreStack<BTList<Variable*>, DLink<Variable*>*> storeVariable;
290 static StoreStack<BTList<Separator*>, DLink<Separator*>*> storeSeparator;
293 static int getDepth()
304 StoreBigInteger::store();
306 storeConstraint.store();
307 storeVariable.store();
308 storeSeparator.store();
312 static void restore()
315 StoreValue::restore();
316 StoreCost::restore();
317 StoreBigInteger::restore();
318 storeDomain.restore();
319 storeConstraint.restore();
320 storeVariable.restore();
321 storeSeparator.restore();
325 static void restore(
int newDepth)
327 assert(depth >= newDepth);
328 while (depth > newDepth)
333#define storeIndexList storeDomain