38 namespace Gecode {
namespace Gist {
42 NodeAllocatorBase<T>::allocate(
void) {
47 n =
static_cast<int>(
n*1.5+1.0);
50 b[cur_b] =
static_cast<Block*
>(
heap.
ralloc(
sizeof(Block)));
58 cur_t = NodeBlockSize-1;
63 for (
int i=cur_b+1;
i--;)
72 if (cur_t==NodeBlockSize)
74 new (&
b[cur_b]->b[cur_t]) T(p);
75 b[cur_b]->best[cur_t] = -1;
76 return cur_b*NodeBlockSize+cur_t;
83 if (cur_t==NodeBlockSize)
85 new (&
b[cur_b]->b[cur_t]) T(root);
86 b[cur_b]->best[cur_t] = -1;
87 return cur_b*NodeBlockSize+cur_t;
93 assert(i/NodeBlockSize <
n);
94 assert(i/NodeBlockSize < cur_b || i%NodeBlockSize <= cur_t);
95 return &(
b[i/NodeBlockSize]->b[i%NodeBlockSize]);
101 assert(i/NodeBlockSize <
n);
102 assert(i/NodeBlockSize < cur_b || i%NodeBlockSize <= cur_t);
103 int bi =
b[i/NodeBlockSize]->best[i%NodeBlockSize];
104 return bi == -1 ? NULL : (*this)[
bi];
110 assert(i/NodeBlockSize <
n);
111 assert(i/NodeBlockSize < cur_b || i%NodeBlockSize <= cur_t);
112 b[i/NodeBlockSize]->best[i%NodeBlockSize] = best;
122 Node::getTag(
void)
const {
123 return static_cast<unsigned int>
124 (
reinterpret_cast<ptrdiff_t
>(childrenOrFirstChild) & 3);
128 Node::setTag(
unsigned int tag) {
130 assert(getTag() == UNDET);
131 childrenOrFirstChild =
reinterpret_cast<void*
>
132 ( (
reinterpret_cast<ptrdiff_t
>(childrenOrFirstChild) & ~(3)) | tag);
136 Node::getPtr(
void)
const {
137 return reinterpret_cast<void*
>
138 (
reinterpret_cast<ptrdiff_t
>(childrenOrFirstChild) & ~(3));
142 Node::getFirstChild(
void)
const {
143 return static_cast<int>
144 ((
reinterpret_cast<ptrdiff_t
>(childrenOrFirstChild) & ~(3)) >> 2);
149 childrenOrFirstChild = NULL;
151 setTag(failed ? LEAF : UNDET);
161 return parent < 0 ? NULL : na[parent];
169 assert(getTag() != UNDET && getTag() != LEAF);
170 if (getTag() == TWO_CHILDREN) {
171 assert(n != 1 || noOfChildren <= 0);
172 return n == 0 ? getFirstChild() : -noOfChildren;
174 assert(n < noOfChildren);
175 return static_cast<int*
>(getPtr())[n];
189 case UNDET:
return 0;
191 case TWO_CHILDREN:
return 1+(noOfChildren <= 0);
192 default:
return noOfChildren;
200 Node*
p = na[parent];