312 Layer* layers = r.alloc<Layer>(a+1);
313 State* states = r.alloc<State>(max_states*(a+1));
315 for (
int i=0; i<max_states*(a+1); i++) {
316 states[i].i_deg = 0; states[i].o_deg = 0;
317 states[i].n_tuples = 0;
318 states[i].tuples =
nullptr;
320 for (
int i=0; i<a+1; i++) {
321 layers[i].states = states + i*max_states;
322 layers[i].n_supports = 0;
326 layers[0].states[0].i_deg = 1;
327 layers[0].states[0].n_tuples = 1;
328 layers[0].states[0].tuples = r.alloc<
int>(1);
329 assert(layers[0].states[0].
tuples !=
nullptr);
332 Edge* edges = r.alloc<Edge>(dfa.
max_degree());
336 for (
int i=0; i<a; i++) {
341 if (layers[i].states[t.i_state()].i_deg != 0) {
343 edges[n_edges].i_state = t.i_state();
344 edges[n_edges].o_state = t.o_state();
347 layers[i].states[t.i_state()].o_deg++;
348 layers[i+1].states[t.o_state()].i_deg++;
350 layers[i+1].states[t.o_state()].n_tuples
351 += layers[i].states[t.i_state()].n_tuples;
357 Support& support = supports[n_supports++];
358 support.val = s.val();
359 support.n_edges = n_edges;
360 support.edges =
Heap::copy(r.alloc<Edge>(n_edges),edges,n_edges);
364 if (n_supports > 0) {
367 layers[i].n_supports = n_supports;
376 if (layers[a].states[s].i_deg != 0U)
377 layers[a].states[s].o_deg = 1U;
381 for (
int i=a; i--; ) {
382 for (
int j = layers[i].n_supports; j--; ) {
383 Support& s = layers[i].supports[j];
384 for (
int k = s.n_edges; k--; ) {
385 int i_state = s.edges[k].i_state;
386 int o_state = s.edges[k].o_state;
388 if (layers[i+1].states[o_state].o_deg == 0) {
390 --layers[i+1].states[o_state].i_deg;
391 --layers[i].states[i_state].o_deg;
393 assert(s.n_edges > 0);
394 s.edges[k] = s.edges[--s.n_edges];
399 layers[i].supports[j] = layers[i].supports[--layers[i].n_supports];
401 if (layers[i].n_supports == 0U) {
408 for (
int i=0; i<a; i++) {
409 for (
int j = layers[i].n_supports; j--; ) {
410 Support& s = layers[i].supports[j];
411 for (
int k = s.n_edges; k--; ) {
412 int i_state = s.edges[k].i_state;
413 int o_state = s.edges[k].o_state;
415 if (layers[i+1].states[o_state].
tuples ==
nullptr) {
416 int n_tuples = layers[i+1].states[o_state].n_tuples;
417 layers[i+1].states[o_state].tuples = r.alloc<
int>((i+1)*n_tuples);
418 layers[i+1].states[o_state].n_tuples = 0;
420 int n = layers[i+1].states[o_state].n_tuples;
422 for (
int t=0; t < layers[i].states[i_state].n_tuples; t++) {
425 &layers[i].states[i_state].
tuples[t*i], i);
427 layers[i+1].states[o_state].tuples[n*(i+1)+t*(i+1)+i] = s.val;
429 layers[i+1].states[o_state].n_tuples
430 += layers[i].states[i_state].n_tuples;
437 for (
int i=0; i<layers[a].states[s].n_tuples; i++) {
438 int* tuple = &layers[a].states[s].tuples[i*a];