@@ -152,6 +152,8 @@ namespace Gecode {
152
152
DFA::init (int start, Transition t_spec[], int f_spec[], bool minimize) {
153
153
using namespace Int ;
154
154
using namespace Extensional ;
155
+ Region region;
156
+
155
157
// Compute number of states and transitions
156
158
int n_states = start;
157
159
int n_trans = 0 ;
@@ -165,12 +167,12 @@ namespace Gecode {
165
167
n_states++;
166
168
167
169
// Temporary structure for transitions
168
- Transition* trans = heap .alloc <Transition>(n_trans);
170
+ Transition* trans = region .alloc <Transition>(n_trans);
169
171
for (int i = n_trans; i--; )
170
172
trans[i] = t_spec[i];
171
173
// Temporary structures for finals
172
- int * final = heap .alloc <int >(n_states+1 );
173
- bool * is_final = heap .alloc <bool >(n_states+1 );
174
+ int * final = region .alloc <int >(n_states+1 );
175
+ bool * is_final = region .alloc <bool >(n_states+1 );
174
176
int n_finals = 0 ;
175
177
for (int i = n_states+1 ; i--; )
176
178
is_final[i] = false ;
@@ -182,7 +184,7 @@ namespace Gecode {
182
184
if (minimize) {
183
185
// Sort transitions by symbol and i_state
184
186
TransBySymbolI_State::sort (trans, n_trans);
185
- Transition** idx = heap .alloc <Transition*>(n_trans+1 );
187
+ Transition** idx = region .alloc <Transition*>(n_trans+1 );
186
188
// idx[i]...idx[i+1]-1 gives where transitions for symbol i start
187
189
int n_symbols = 0 ;
188
190
{
@@ -197,9 +199,9 @@ namespace Gecode {
197
199
assert (j == n_trans);
198
200
}
199
201
// Map states to groups
200
- int * s2g = heap .alloc <int >(n_states+1 );
201
- StateGroup* part = heap .alloc <StateGroup>(n_states+1 );
202
- GroupStates* g2s = heap .alloc <GroupStates>(n_states+1 );
202
+ int * s2g = region .alloc <int >(n_states+1 );
203
+ StateGroup* part = region .alloc <StateGroup>(n_states+1 );
204
+ GroupStates* g2s = region .alloc <GroupStates>(n_states+1 );
203
205
// Initialize: final states is group one, all other group zero
204
206
for (int i = n_states+1 ; i--; ) {
205
207
part[i].state = i;
@@ -287,7 +289,7 @@ namespace Gecode {
287
289
break ;
288
290
}
289
291
// Compute representatives
290
- int * s2r = heap .alloc <int >(n_states+1 );
292
+ int * s2r = region .alloc <int >(n_states+1 );
291
293
for (int i = n_states+1 ; i--; )
292
294
s2r[i] = -1 ;
293
295
for (int g = n_groups; g--; )
@@ -303,21 +305,16 @@ namespace Gecode {
303
305
}
304
306
n_trans = j;
305
307
n_states = n_groups;
306
- heap.free <int >(s2r,n_states+1 );
307
308
}
308
- heap.free <GroupStates>(g2s,n_states+1 );
309
- heap.free <StateGroup>(part,n_states+1 );
310
- heap.free <int >(s2g,n_states+1 );
311
- heap.free <Transition*>(idx,n_trans+1 );
312
309
}
313
310
314
311
// Do a reachability analysis for all states starting from start state
315
- Gecode::Support::StaticStack<int ,Heap > visit (heap ,n_states);
316
- int * state = heap .alloc <int >(n_states);
312
+ Gecode::Support::StaticStack<int ,Region > visit (region ,n_states);
313
+ int * state = region .alloc <int >(n_states);
317
314
for (int i=n_states; i--; )
318
315
state[i] = SI_NONE;
319
316
320
- Transition** idx = heap .alloc <Transition*>(n_states+1 );
317
+ Transition** idx = region .alloc <Transition*>(n_states+1 );
321
318
{
322
319
// Sort all transitions according to i_state and create index structure
323
320
// idx[i]...idx[i+1]-1 gives where transitions for state i start
@@ -374,12 +371,9 @@ namespace Gecode {
374
371
}
375
372
}
376
373
}
377
- heap.free <Transition*>(idx,n_states+1 );
378
- heap.free <int >(final ,n_states+1 );
379
- heap.free <bool >(is_final,n_states+1 );
380
374
381
375
// Now all reachable states are known (also the final ones)
382
- int * re = heap .alloc <int >(n_states);
376
+ int * re = region .alloc <int >(n_states);
383
377
for (int i = n_states; i--; )
384
378
re[i] = -1 ;
385
379
@@ -440,7 +434,7 @@ namespace Gecode {
440
434
{
441
435
// Compute maximal degree
442
436
unsigned int max_degree = 0 ;
443
- unsigned int * deg = heap .alloc <unsigned int >(m_states);
437
+ unsigned int * deg = region .alloc <unsigned int >(m_states);
444
438
445
439
// Compute in-degree per state
446
440
for (int i = m_states; i--; )
@@ -458,8 +452,6 @@ namespace Gecode {
458
452
for (int i = m_states; i--; )
459
453
max_degree = std::max (max_degree,deg[i]);
460
454
461
- heap.free <unsigned int >(deg,m_states);
462
-
463
455
// Compute transitions per symbol
464
456
{
465
457
int i=0 ;
@@ -477,9 +469,6 @@ namespace Gecode {
477
469
478
470
d->fill ();
479
471
object (d);
480
- heap.free <int >(re,n_states);
481
- heap.free <int >(state,n_states);
482
- heap.free <Transition>(trans,n_trans);
483
472
}
484
473
485
474
DFA::DFA (int start, Transition t_spec[], int f_spec[], bool minimize) {
0 commit comments