summaryrefslogtreecommitdiff
path: root/tblcmp.c
diff options
context:
space:
mode:
authorVern Paxson <vern@ee.lbl.gov>1993-04-14 22:41:35 +0000
committerVern Paxson <vern@ee.lbl.gov>1993-04-14 22:41:35 +0000
commitda65ac15e3bf4e7391dc967aed49394798d21bf5 (patch)
treea902cd44cadb4d8e8e5a3901b244dad56a852aae /tblcmp.c
parent38bb4c0fcd54539764cf2db73d3cc58d60cdc579 (diff)
Reformatting.
Diffstat (limited to 'tblcmp.c')
-rw-r--r--tblcmp.c1137
1 files changed, 553 insertions, 584 deletions
diff --git a/tblcmp.c b/tblcmp.c
index 7e4f74a..26e7cb6 100644
--- a/tblcmp.c
+++ b/tblcmp.c
@@ -80,237 +80,243 @@ int tbldiff PROTO((int[], int, int[]));
void bldtbl( state, statenum, totaltrans, comstate, comfreq )
int state[], statenum, totaltrans, comstate, comfreq;
+ {
+ int extptr, extrct[2][CSIZE + 1];
+ int mindiff, minprot, i, d;
+
+ /* If extptr is 0 then the first array of extrct holds the result
+ * of the "best difference" to date, which is those transitions
+ * which occur in "state" but not in the proto which, to date,
+ * has the fewest differences between itself and "state". If
+ * extptr is 1 then the second array of extrct hold the best
+ * difference. The two arrays are toggled between so that the
+ * best difference to date can be kept around and also a difference
+ * just created by checking against a candidate "best" proto.
+ */
- {
- int extptr, extrct[2][CSIZE + 1];
- int mindiff, minprot, i, d;
- int checkcom;
+ extptr = 0;
- /* If extptr is 0 then the first array of extrct holds the result of the
- * "best difference" to date, which is those transitions which occur in
- * "state" but not in the proto which, to date, has the fewest differences
- * between itself and "state". If extptr is 1 then the second array of
- * extrct hold the best difference. The two arrays are toggled
- * between so that the best difference to date can be kept around and
- * also a difference just created by checking against a candidate "best"
- * proto.
- */
+ /* If the state has too few out-transitions, don't bother trying to
+ * compact its tables.
+ */
- extptr = 0;
+ if ( (totaltrans * 100) < (numecs * PROTO_SIZE_PERCENTAGE) )
+ mkentry( state, numecs, statenum, JAMSTATE, totaltrans );
- /* if the state has too few out-transitions, don't bother trying to
- * compact its tables
- */
+ else
+ {
+ /* "checkcom" is true if we should only check "state" against
+ * protos which have the same "comstate" value.
+ */
+ int checkcom =
+ comfreq * 100 > totaltrans * CHECK_COM_PERCENTAGE;
- if ( (totaltrans * 100) < (numecs * PROTO_SIZE_PERCENTAGE) )
- mkentry( state, numecs, statenum, JAMSTATE, totaltrans );
+ minprot = firstprot;
+ mindiff = totaltrans;
+
+ if ( checkcom )
+ {
+ /* Find first proto which has the same "comstate". */
+ for ( i = firstprot; i != NIL; i = protnext[i] )
+ if ( protcomst[i] == comstate )
+ {
+ minprot = i;
+ mindiff = tbldiff( state, minprot,
+ extrct[extptr] );
+ break;
+ }
+ }
- else
- {
- /* checkcom is true if we should only check "state" against
- * protos which have the same "comstate" value
- */
+ else
+ {
+ /* Since we've decided that the most common destination
+ * out of "state" does not occur with a high enough
+ * frequency, we set the "comstate" to zero, assuring
+ * that if this state is entered into the proto list,
+ * it will not be considered a template.
+ */
+ comstate = 0;
+
+ if ( firstprot != NIL )
+ {
+ minprot = firstprot;
+ mindiff = tbldiff( state, minprot,
+ extrct[extptr] );
+ }
+ }
- checkcom = comfreq * 100 > totaltrans * CHECK_COM_PERCENTAGE;
+ /* We now have the first interesting proto in "minprot". If
+ * it matches within the tolerances set for the first proto,
+ * we don't want to bother scanning the rest of the proto list
+ * to see if we have any other reasonable matches.
+ */
- minprot = firstprot;
- mindiff = totaltrans;
+ if ( mindiff * 100 > totaltrans * FIRST_MATCH_DIFF_PERCENTAGE )
+ {
+ /* Not a good enough match. Scan the rest of the
+ * protos.
+ */
+ for ( i = minprot; i != NIL; i = protnext[i] )
+ {
+ d = tbldiff( state, i, extrct[1 - extptr] );
+ if ( d < mindiff )
+ {
+ extptr = 1 - extptr;
+ mindiff = d;
+ minprot = i;
+ }
+ }
+ }
- if ( checkcom )
- {
- /* find first proto which has the same "comstate" */
- for ( i = firstprot; i != NIL; i = protnext[i] )
- if ( protcomst[i] == comstate )
- {
- minprot = i;
- mindiff = tbldiff( state, minprot, extrct[extptr] );
- break;
- }
- }
+ /* Check if the proto we've decided on as our best bet is close
+ * enough to the state we want to match to be usable.
+ */
- else
- {
- /* since we've decided that the most common destination out
- * of "state" does not occur with a high enough frequency,
- * we set the "comstate" to zero, assuring that if this state
- * is entered into the proto list, it will not be considered
- * a template.
- */
- comstate = 0;
-
- if ( firstprot != NIL )
- {
- minprot = firstprot;
- mindiff = tbldiff( state, minprot, extrct[extptr] );
- }
- }
+ if ( mindiff * 100 > totaltrans * ACCEPTABLE_DIFF_PERCENTAGE )
+ {
+ /* No good. If the state is homogeneous enough,
+ * we make a template out of it. Otherwise, we
+ * make a proto.
+ */
- /* we now have the first interesting proto in "minprot". If
- * it matches within the tolerances set for the first proto,
- * we don't want to bother scanning the rest of the proto list
- * to see if we have any other reasonable matches.
- */
+ if ( comfreq * 100 >=
+ totaltrans * TEMPLATE_SAME_PERCENTAGE )
+ mktemplate( state, statenum, comstate );
- if ( mindiff * 100 > totaltrans * FIRST_MATCH_DIFF_PERCENTAGE )
- { /* not a good enough match. Scan the rest of the protos */
- for ( i = minprot; i != NIL; i = protnext[i] )
- {
- d = tbldiff( state, i, extrct[1 - extptr] );
- if ( d < mindiff )
- {
- extptr = 1 - extptr;
- mindiff = d;
- minprot = i;
- }
- }
- }
+ else
+ {
+ mkprot( state, statenum, comstate );
+ mkentry( state, numecs, statenum,
+ JAMSTATE, totaltrans );
+ }
+ }
- /* check if the proto we've decided on as our best bet is close
- * enough to the state we want to match to be usable
- */
+ else
+ { /* use the proto */
+ mkentry( extrct[extptr], numecs, statenum,
+ prottbl[minprot], mindiff );
- if ( mindiff * 100 > totaltrans * ACCEPTABLE_DIFF_PERCENTAGE )
- {
- /* no good. If the state is homogeneous enough, we make a
- * template out of it. Otherwise, we make a proto.
- */
+ /* If this state was sufficiently different from the
+ * proto we built it from, make it, too, a proto.
+ */
- if ( comfreq * 100 >= totaltrans * TEMPLATE_SAME_PERCENTAGE )
- mktemplate( state, statenum, comstate );
+ if ( mindiff * 100 >=
+ totaltrans * NEW_PROTO_DIFF_PERCENTAGE )
+ mkprot( state, statenum, comstate );
+
+ /* Since mkprot added a new proto to the proto queue,
+ * it's possible that "minprot" is no longer on the
+ * proto queue (if it happened to have been the last
+ * entry, it would have been bumped off). If it's
+ * not there, then the new proto took its physical
+ * place (though logically the new proto is at the
+ * beginning of the queue), so in that case the
+ * following call will do nothing.
+ */
- else
- {
- mkprot( state, statenum, comstate );
- mkentry( state, numecs, statenum, JAMSTATE, totaltrans );
+ mv2front( minprot );
+ }
}
- }
-
- else
- { /* use the proto */
- mkentry( extrct[extptr], numecs, statenum,
- prottbl[minprot], mindiff );
-
- /* if this state was sufficiently different from the proto
- * we built it from, make it, too, a proto
- */
-
- if ( mindiff * 100 >= totaltrans * NEW_PROTO_DIFF_PERCENTAGE )
- mkprot( state, statenum, comstate );
-
- /* since mkprot added a new proto to the proto queue, it's possible
- * that "minprot" is no longer on the proto queue (if it happened
- * to have been the last entry, it would have been bumped off).
- * If it's not there, then the new proto took its physical place
- * (though logically the new proto is at the beginning of the
- * queue), so in that case the following call will do nothing.
- */
-
- mv2front( minprot );
- }
}
- }
/* cmptmps - compress template table entries
*
- * synopsis
- * cmptmps();
- *
- * template tables are compressed by using the 'template equivalence
- * classes', which are collections of transition character equivalence
- * classes which always appear together in templates - really meta-equivalence
- * classes. until this point, the tables for templates have been stored
- * up at the top end of the nxt array; they will now be compressed and have
- * table entries made for them.
+ * Template tables are compressed by using the 'template equivalence
+ * classes', which are collections of transition character equivalence
+ * classes which always appear together in templates - really meta-equivalence
+ * classes. until this point, the tables for templates have been stored
+ * up at the top end of the nxt array; they will now be compressed and have
+ * table entries made for them.
*/
void cmptmps()
-
- {
- int tmpstorage[CSIZE + 1];
- register int *tmp = tmpstorage, i, j;
- int totaltrans, trans;
-
- peakpairs = numtemps * numecs + tblend;
-
- if ( usemecs )
{
- /* create equivalence classes based on data gathered on template
- * transitions
- */
+ int tmpstorage[CSIZE + 1];
+ register int *tmp = tmpstorage, i, j;
+ int totaltrans, trans;
- nummecs = cre8ecs( tecfwd, tecbck, numecs );
- }
-
- else
- nummecs = numecs;
+ peakpairs = numtemps * numecs + tblend;
- while ( lastdfa + numtemps + 1 >= current_max_dfas )
- increase_max_dfas();
+ if ( usemecs )
+ {
+ /* Create equivalence classes based on data gathered on
+ * template transitions.
+ */
+ nummecs = cre8ecs( tecfwd, tecbck, numecs );
+ }
- /* loop through each template */
+ else
+ nummecs = numecs;
- for ( i = 1; i <= numtemps; ++i )
- {
- totaltrans = 0; /* number of non-jam transitions out of this template */
+ while ( lastdfa + numtemps + 1 >= current_max_dfas )
+ increase_max_dfas();
- for ( j = 1; j <= numecs; ++j )
- {
- trans = tnxt[numecs * i + j];
+ /* Loop through each template. */
- if ( usemecs )
+ for ( i = 1; i <= numtemps; ++i )
{
- /* the absolute value of tecbck is the meta-equivalence class
- * of a given equivalence class, as set up by cre8ecs
- */
- if ( tecbck[j] > 0 )
- {
- tmp[tecbck[j]] = trans;
-
- if ( trans > 0 )
- ++totaltrans;
- }
- }
+ /* Number of non-jam transitions out of this template. */
+ totaltrans = 0;
+
+ for ( j = 1; j <= numecs; ++j )
+ {
+ trans = tnxt[numecs * i + j];
+
+ if ( usemecs )
+ {
+ /* The absolute value of tecbck is the
+ * meta-equivalence class of a given
+ * equivalence class, as set up by cre8ecs().
+ */
+ if ( tecbck[j] > 0 )
+ {
+ tmp[tecbck[j]] = trans;
+
+ if ( trans > 0 )
+ ++totaltrans;
+ }
+ }
+
+ else
+ {
+ tmp[j] = trans;
+
+ if ( trans > 0 )
+ ++totaltrans;
+ }
+ }
- else
- {
- tmp[j] = trans;
+ /* It is assumed (in a rather subtle way) in the skeleton
+ * that if we're using meta-equivalence classes, the def[]
+ * entry for all templates is the jam template, i.e.,
+ * templates never default to other non-jam table entries
+ * (e.g., another template)
+ */
- if ( trans > 0 )
- ++totaltrans;
+ /* Leave room for the jam-state after the last real state. */
+ mkentry( tmp, nummecs, lastdfa + i + 1, JAMSTATE, totaltrans );
}
- }
-
- /* it is assumed (in a rather subtle way) in the skeleton that
- * if we're using meta-equivalence classes, the def[] entry for
- * all templates is the jam template, i.e., templates never default
- * to other non-jam table entries (e.g., another template)
- */
-
- /* leave room for the jam-state after the last real state */
- mkentry( tmp, nummecs, lastdfa + i + 1, JAMSTATE, totaltrans );
}
- }
/* expand_nxt_chk - expand the next check arrays */
void expand_nxt_chk()
+ {
+ register int old_max = current_max_xpairs;
- {
- register int old_max = current_max_xpairs;
-
- current_max_xpairs += MAX_XPAIRS_INCREMENT;
+ current_max_xpairs += MAX_XPAIRS_INCREMENT;
- ++num_reallocs;
+ ++num_reallocs;
- nxt = reallocate_integer_array( nxt, current_max_xpairs );
- chk = reallocate_integer_array( chk, current_max_xpairs );
+ nxt = reallocate_integer_array( nxt, current_max_xpairs );
+ chk = reallocate_integer_array( chk, current_max_xpairs );
- zero_out( (char *) (chk + old_max),
- MAX_XPAIRS_INCREMENT * sizeof( int ) / sizeof( char ) );
- }
+ zero_out( (char *) (chk + old_max),
+ MAX_XPAIRS_INCREMENT * sizeof( int ) / sizeof( char ) );
+ }
/* find_table_space - finds a space in the table for a state to be placed
@@ -334,170 +340,167 @@ void expand_nxt_chk()
int find_table_space( state, numtrans )
int *state, numtrans;
-
- {
- /* firstfree is the position of the first possible occurrence of two
- * consecutive unused records in the chk and nxt arrays
- */
- register int i;
- register int *state_ptr, *chk_ptr;
- register int *ptr_to_last_entry_in_state;
-
- /* if there are too many out-transitions, put the state at the end of
- * nxt and chk
- */
- if ( numtrans > MAX_XTIONS_FULL_INTERIOR_FIT )
{
- /* if table is empty, return the first available spot in chk/nxt,
- * which should be 1
+ /* Firstfree is the position of the first possible occurrence of two
+ * consecutive unused records in the chk and nxt arrays.
*/
- if ( tblend < 2 )
- return ( 1 );
-
- i = tblend - numecs; /* start searching for table space near the
- * end of chk/nxt arrays
- */
- }
-
- else
- i = firstfree; /* start searching for table space from the
- * beginning (skipping only the elements
- * which will definitely not hold the new
- * state)
- */
+ register int i;
+ register int *state_ptr, *chk_ptr;
+ register int *ptr_to_last_entry_in_state;
- while ( 1 ) /* loops until a space is found */
- {
- while ( i + numecs >= current_max_xpairs )
- expand_nxt_chk();
-
- /* loops until space for end-of-buffer and action number are found */
- while ( 1 )
- {
- if ( chk[i - 1] == 0 ) /* check for action number space */
+ /* If there are too many out-transitions, put the state at the end of
+ * nxt and chk.
+ */
+ if ( numtrans > MAX_XTIONS_FULL_INTERIOR_FIT )
{
- if ( chk[i] == 0 ) /* check for end-of-buffer space */
- break;
+ /* If table is empty, return the first available spot in
+ * chk/nxt, which should be 1.
+ */
+ if ( tblend < 2 )
+ return 1;
- else
- i += 2; /* since i != 0, there is no use checking to
- * see if (++i) - 1 == 0, because that's the
- * same as i == 0, so we skip a space
- */
+ /* Start searching for table space near the end of
+ * chk/nxt arrays.
+ */
+ i = tblend - numecs;
}
- else
- ++i;
+ else
+ /* Start searching for table space from the beginning
+ * (skipping only the elements which will definitely not
+ * hold the new state).
+ */
+ i = firstfree;
- while ( i + numecs >= current_max_xpairs )
- expand_nxt_chk();
- }
+ while ( 1 ) /* loops until a space is found */
+ {
+ while ( i + numecs >= current_max_xpairs )
+ expand_nxt_chk();
- /* if we started search from the beginning, store the new firstfree for
- * the next call of find_table_space()
- */
- if ( numtrans <= MAX_XTIONS_FULL_INTERIOR_FIT )
- firstfree = i + 1;
+ /* Loops until space for end-of-buffer and action number
+ * are found.
+ */
+ while ( 1 )
+ {
+ /* Check for action number space. */
+ if ( chk[i - 1] == 0 )
+ {
+ /* Check for end-of-buffer space. */
+ if ( chk[i] == 0 )
+ break;
+
+ else
+ /* Since i != 0, there is no use
+ * checking to see if (++i) - 1 == 0,
+ * because that's the same as i == 0,
+ * so we skip a space.
+ */
+ i += 2;
+ }
+
+ else
+ ++i;
+
+ while ( i + numecs >= current_max_xpairs )
+ expand_nxt_chk();
+ }
- /* check to see if all elements in chk (and therefore nxt) that are
- * needed for the new state have not yet been taken
- */
+ /* If we started search from the beginning, store the new
+ * firstfree for the next call of find_table_space().
+ */
+ if ( numtrans <= MAX_XTIONS_FULL_INTERIOR_FIT )
+ firstfree = i + 1;
- state_ptr = &state[1];
- ptr_to_last_entry_in_state = &chk[i + numecs + 1];
+ /* Check to see if all elements in chk (and therefore nxt)
+ * that are needed for the new state have not yet been taken.
+ */
- for ( chk_ptr = &chk[i + 1]; chk_ptr != ptr_to_last_entry_in_state;
- ++chk_ptr )
- if ( *(state_ptr++) != 0 && *chk_ptr != 0 )
- break;
+ state_ptr = &state[1];
+ ptr_to_last_entry_in_state = &chk[i + numecs + 1];
- if ( chk_ptr == ptr_to_last_entry_in_state )
- return ( i );
+ for ( chk_ptr = &chk[i + 1];
+ chk_ptr != ptr_to_last_entry_in_state; ++chk_ptr )
+ if ( *(state_ptr++) != 0 && *chk_ptr != 0 )
+ break;
- else
- ++i;
+ if ( chk_ptr == ptr_to_last_entry_in_state )
+ return i;
+
+ else
+ ++i;
+ }
}
- }
/* inittbl - initialize transition tables
*
- * synopsis
- * inittbl();
- *
* Initializes "firstfree" to be one beyond the end of the table. Initializes
* all "chk" entries to be zero. Note that templates are built in their
* own tbase/tdef tables. They are shifted down to be contiguous
* with the non-template entries during table generation.
*/
void inittbl()
+ {
+ register int i;
- {
- register int i;
-
- zero_out( (char *) chk,
- current_max_xpairs * sizeof( int ) / sizeof( char ) );
+ zero_out( (char *) chk,
+ current_max_xpairs * sizeof( int ) / sizeof( char ) );
- tblend = 0;
- firstfree = tblend + 1;
- numtemps = 0;
+ tblend = 0;
+ firstfree = tblend + 1;
+ numtemps = 0;
- if ( usemecs )
- {
- /* set up doubly-linked meta-equivalence classes
- * these are sets of equivalence classes which all have identical
- * transitions out of TEMPLATES
- */
+ if ( usemecs )
+ {
+ /* Set up doubly-linked meta-equivalence classes; these
+ * are sets of equivalence classes which all have identical
+ * transitions out of TEMPLATES.
+ */
- tecbck[1] = NIL;
+ tecbck[1] = NIL;
- for ( i = 2; i <= numecs; ++i )
- {
- tecbck[i] = i - 1;
- tecfwd[i - 1] = i;
- }
+ for ( i = 2; i <= numecs; ++i )
+ {
+ tecbck[i] = i - 1;
+ tecfwd[i - 1] = i;
+ }
- tecfwd[numecs] = NIL;
+ tecfwd[numecs] = NIL;
+ }
}
- }
-/* mkdeftbl - make the default, "jam" table entries
- *
- * synopsis
- * mkdeftbl();
- */
+/* mkdeftbl - make the default, "jam" table entries */
void mkdeftbl()
+ {
+ int i;
- {
- int i;
-
- jamstate = lastdfa + 1;
+ jamstate = lastdfa + 1;
- ++tblend; /* room for transition on end-of-buffer character */
+ ++tblend; /* room for transition on end-of-buffer character */
- while ( tblend + numecs >= current_max_xpairs )
- expand_nxt_chk();
+ while ( tblend + numecs >= current_max_xpairs )
+ expand_nxt_chk();
- /* add in default end-of-buffer transition */
- nxt[tblend] = end_of_buffer_state;
- chk[tblend] = jamstate;
+ /* Add in default end-of-buffer transition. */
+ nxt[tblend] = end_of_buffer_state;
+ chk[tblend] = jamstate;
- for ( i = 1; i <= numecs; ++i )
- {
- nxt[tblend + i] = 0;
- chk[tblend + i] = jamstate;
- }
+ for ( i = 1; i <= numecs; ++i )
+ {
+ nxt[tblend + i] = 0;
+ chk[tblend + i] = jamstate;
+ }
- jambase = tblend;
+ jambase = tblend;
- base[jamstate] = jambase;
- def[jamstate] = 0;
+ base[jamstate] = jambase;
+ def[jamstate] = 0;
- tblend += numecs;
- ++numtemps;
- }
+ tblend += numecs;
+ ++numtemps;
+ }
/* mkentry - create base/def and nxt/chk entries for transition array
@@ -522,300 +525,274 @@ void mkdeftbl()
void mkentry( state, numchars, statenum, deflink, totaltrans )
register int *state;
int numchars, statenum, deflink, totaltrans;
+ {
+ register int minec, maxec, i, baseaddr;
+ int tblbase, tbllast;
- {
- register int minec, maxec, i, baseaddr;
- int tblbase, tbllast;
+ if ( totaltrans == 0 )
+ { /* there are no out-transitions */
+ if ( deflink == JAMSTATE )
+ base[statenum] = JAMSTATE;
+ else
+ base[statenum] = 0;
- if ( totaltrans == 0 )
- { /* there are no out-transitions */
- if ( deflink == JAMSTATE )
- base[statenum] = JAMSTATE;
- else
- base[statenum] = 0;
+ def[statenum] = deflink;
+ return;
+ }
- def[statenum] = deflink;
- return;
- }
+ for ( minec = 1; minec <= numchars; ++minec )
+ {
+ if ( state[minec] != SAME_TRANS )
+ if ( state[minec] != 0 || deflink != JAMSTATE )
+ break;
+ }
- for ( minec = 1; minec <= numchars; ++minec )
- {
- if ( state[minec] != SAME_TRANS )
- if ( state[minec] != 0 || deflink != JAMSTATE )
- break;
- }
+ if ( totaltrans == 1 )
+ {
+ /* There's only one out-transition. Save it for later to fill
+ * in holes in the tables.
+ */
+ stack1( statenum, minec, state[minec], deflink );
+ return;
+ }
- if ( totaltrans == 1 )
- {
- /* there's only one out-transition. Save it for later to fill
- * in holes in the tables.
- */
- stack1( statenum, minec, state[minec], deflink );
- return;
- }
+ for ( maxec = numchars; maxec > 0; --maxec )
+ {
+ if ( state[maxec] != SAME_TRANS )
+ if ( state[maxec] != 0 || deflink != JAMSTATE )
+ break;
+ }
- for ( maxec = numchars; maxec > 0; --maxec )
- {
- if ( state[maxec] != SAME_TRANS )
- if ( state[maxec] != 0 || deflink != JAMSTATE )
- break;
- }
+ /* Whether we try to fit the state table in the middle of the table
+ * entries we have already generated, or if we just take the state
+ * table at the end of the nxt/chk tables, we must make sure that we
+ * have a valid base address (i.e., non-negative). Note that not
+ * only are negative base addresses dangerous at run-time (because
+ * indexing the next array with one and a low-valued character might
+ * generate an array-out-of-bounds error message), but at compile-time
+ * negative base addresses denote TEMPLATES.
+ */
- /* Whether we try to fit the state table in the middle of the table
- * entries we have already generated, or if we just take the state
- * table at the end of the nxt/chk tables, we must make sure that we
- * have a valid base address (i.e., non-negative). Note that not only are
- * negative base addresses dangerous at run-time (because indexing the
- * next array with one and a low-valued character might generate an
- * array-out-of-bounds error message), but at compile-time negative
- * base addresses denote TEMPLATES.
- */
-
- /* find the first transition of state that we need to worry about. */
- if ( totaltrans * 100 <= numchars * INTERIOR_FIT_PERCENTAGE )
- { /* attempt to squeeze it into the middle of the tabls */
- baseaddr = firstfree;
-
- while ( baseaddr < minec )
- {
- /* using baseaddr would result in a negative base address below
- * find the next free slot
- */
- for ( ++baseaddr; chk[baseaddr] != 0; ++baseaddr )
- ;
- }
-
- while ( baseaddr + maxec - minec + 1 >= current_max_xpairs )
- expand_nxt_chk();
+ /* Find the first transition of state that we need to worry about. */
+ if ( totaltrans * 100 <= numchars * INTERIOR_FIT_PERCENTAGE )
+ {
+ /* Attempt to squeeze it into the middle of the tables. */
+ baseaddr = firstfree;
- for ( i = minec; i <= maxec; ++i )
- if ( state[i] != SAME_TRANS )
- if ( state[i] != 0 || deflink != JAMSTATE )
- if ( chk[baseaddr + i - minec] != 0 )
- { /* baseaddr unsuitable - find another */
- for ( ++baseaddr;
- baseaddr < current_max_xpairs &&
- chk[baseaddr] != 0;
- ++baseaddr )
- ;
-
- while ( baseaddr + maxec - minec + 1 >=
- current_max_xpairs )
- expand_nxt_chk();
-
- /* reset the loop counter so we'll start all
- * over again next time it's incremented
+ while ( baseaddr < minec )
+ {
+ /* Using baseaddr would result in a negative base
+ * address below; find the next free slot.
*/
-
- i = minec - 1;
+ for ( ++baseaddr; chk[baseaddr] != 0; ++baseaddr )
+ ;
}
- }
- else
- {
- /* ensure that the base address we eventually generate is
- * non-negative
- */
- baseaddr = max( tblend + 1, minec );
- }
-
- tblbase = baseaddr - minec;
- tbllast = tblbase + maxec;
-
- while ( tbllast + 1 >= current_max_xpairs )
- expand_nxt_chk();
+ while ( baseaddr + maxec - minec + 1 >= current_max_xpairs )
+ expand_nxt_chk();
+
+ for ( i = minec; i <= maxec; ++i )
+ if ( state[i] != SAME_TRANS &&
+ (state[i] != 0 || deflink != JAMSTATE) &&
+ chk[baseaddr + i - minec] != 0 )
+ { /* baseaddr unsuitable - find another */
+ for ( ++baseaddr;
+ baseaddr < current_max_xpairs &&
+ chk[baseaddr] != 0; ++baseaddr )
+ ;
+
+ while ( baseaddr + maxec - minec + 1 >=
+ current_max_xpairs )
+ expand_nxt_chk();
+
+ /* Reset the loop counter so we'll start all
+ * over again next time it's incremented.
+ */
- base[statenum] = tblbase;
- def[statenum] = deflink;
+ i = minec - 1;
+ }
+ }
- for ( i = minec; i <= maxec; ++i )
- if ( state[i] != SAME_TRANS )
- if ( state[i] != 0 || deflink != JAMSTATE )
+ else
{
- nxt[tblbase + i] = state[i];
- chk[tblbase + i] = statenum;
+ /* Ensure that the base address we eventually generate is
+ * non-negative.
+ */
+ baseaddr = max( tblend + 1, minec );
}
- if ( baseaddr == firstfree )
- /* find next free slot in tables */
- for ( ++firstfree; chk[firstfree] != 0; ++firstfree )
- ;
+ tblbase = baseaddr - minec;
+ tbllast = tblbase + maxec;
- tblend = max( tblend, tbllast );
- }
+ while ( tbllast + 1 >= current_max_xpairs )
+ expand_nxt_chk();
+
+ base[statenum] = tblbase;
+ def[statenum] = deflink;
+
+ for ( i = minec; i <= maxec; ++i )
+ if ( state[i] != SAME_TRANS )
+ if ( state[i] != 0 || deflink != JAMSTATE )
+ {
+ nxt[tblbase + i] = state[i];
+ chk[tblbase + i] = statenum;
+ }
+
+ if ( baseaddr == firstfree )
+ /* Find next free slot in tables. */
+ for ( ++firstfree; chk[firstfree] != 0; ++firstfree )
+ ;
+
+ tblend = max( tblend, tbllast );
+ }
/* mk1tbl - create table entries for a state (or state fragment) which
* has only one out-transition
- *
- * synopsis
- * int state, sym, onenxt, onedef;
- * mk1tbl( state, sym, onenxt, onedef );
*/
void mk1tbl( state, sym, onenxt, onedef )
int state, sym, onenxt, onedef;
+ {
+ if ( firstfree < sym )
+ firstfree = sym;
- {
- if ( firstfree < sym )
- firstfree = sym;
-
- while ( chk[firstfree] != 0 )
- if ( ++firstfree >= current_max_xpairs )
- expand_nxt_chk();
+ while ( chk[firstfree] != 0 )
+ if ( ++firstfree >= current_max_xpairs )
+ expand_nxt_chk();
- base[state] = firstfree - sym;
- def[state] = onedef;
- chk[firstfree] = state;
- nxt[firstfree] = onenxt;
+ base[state] = firstfree - sym;
+ def[state] = onedef;
+ chk[firstfree] = state;
+ nxt[firstfree] = onenxt;
- if ( firstfree > tblend )
- {
- tblend = firstfree++;
+ if ( firstfree > tblend )
+ {
+ tblend = firstfree++;
- if ( firstfree >= current_max_xpairs )
- expand_nxt_chk();
+ if ( firstfree >= current_max_xpairs )
+ expand_nxt_chk();
+ }
}
- }
-/* mkprot - create new proto entry
- *
- * synopsis
- * int state[], statenum, comstate;
- * mkprot( state, statenum, comstate );
- */
+/* mkprot - create new proto entry */
void mkprot( state, statenum, comstate )
int state[], statenum, comstate;
-
- {
- int i, slot, tblbase;
-
- if ( ++numprots >= MSP || numecs * numprots >= PROT_SAVE_SIZE )
{
- /* gotta make room for the new proto by dropping last entry in
- * the queue
- */
- slot = lastprot;
- lastprot = protprev[lastprot];
- protnext[lastprot] = NIL;
- }
+ int i, slot, tblbase;
- else
- slot = numprots;
+ if ( ++numprots >= MSP || numecs * numprots >= PROT_SAVE_SIZE )
+ {
+ /* Gotta make room for the new proto by dropping last entry in
+ * the queue.
+ */
+ slot = lastprot;
+ lastprot = protprev[lastprot];
+ protnext[lastprot] = NIL;
+ }
- protnext[slot] = firstprot;
+ else
+ slot = numprots;
- if ( firstprot != NIL )
- protprev[firstprot] = slot;
+ protnext[slot] = firstprot;
- firstprot = slot;
- prottbl[slot] = statenum;
- protcomst[slot] = comstate;
+ if ( firstprot != NIL )
+ protprev[firstprot] = slot;
- /* copy state into save area so it can be compared with rapidly */
- tblbase = numecs * (slot - 1);
+ firstprot = slot;
+ prottbl[slot] = statenum;
+ protcomst[slot] = comstate;
- for ( i = 1; i <= numecs; ++i )
- protsave[tblbase + i] = state[i];
- }
+ /* Copy state into save area so it can be compared with rapidly. */
+ tblbase = numecs * (slot - 1);
+
+ for ( i = 1; i <= numecs; ++i )
+ protsave[tblbase + i] = state[i];
+ }
/* mktemplate - create a template entry based on a state, and connect the state
* to it
- *
- * synopsis
- * int state[], statenum, comstate, totaltrans;
- * mktemplate( state, statenum, comstate, totaltrans );
*/
void mktemplate( state, statenum, comstate )
int state[], statenum, comstate;
+ {
+ int i, numdiff, tmpbase, tmp[CSIZE + 1];
+ Char transset[CSIZE + 1];
+ int tsptr;
- {
- int i, numdiff, tmpbase, tmp[CSIZE + 1];
- Char transset[CSIZE + 1];
- int tsptr;
-
- ++numtemps;
+ ++numtemps;
- tsptr = 0;
+ tsptr = 0;
- /* calculate where we will temporarily store the transition table
- * of the template in the tnxt[] array. The final transition table
- * gets created by cmptmps()
- */
+ /* Calculate where we will temporarily store the transition table
+ * of the template in the tnxt[] array. The final transition table
+ * gets created by cmptmps().
+ */
- tmpbase = numtemps * numecs;
+ tmpbase = numtemps * numecs;
- if ( tmpbase + numecs >= current_max_template_xpairs )
- {
- current_max_template_xpairs += MAX_TEMPLATE_XPAIRS_INCREMENT;
+ if ( tmpbase + numecs >= current_max_template_xpairs )
+ {
+ current_max_template_xpairs += MAX_TEMPLATE_XPAIRS_INCREMENT;
- ++num_reallocs;
+ ++num_reallocs;
- tnxt = reallocate_integer_array( tnxt, current_max_template_xpairs );
- }
+ tnxt = reallocate_integer_array( tnxt,
+ current_max_template_xpairs );
+ }
- for ( i = 1; i <= numecs; ++i )
- if ( state[i] == 0 )
- tnxt[tmpbase + i] = 0;
- else
- {
- transset[tsptr++] = i;
- tnxt[tmpbase + i] = comstate;
- }
+ for ( i = 1; i <= numecs; ++i )
+ if ( state[i] == 0 )
+ tnxt[tmpbase + i] = 0;
+ else
+ {
+ transset[tsptr++] = i;
+ tnxt[tmpbase + i] = comstate;
+ }
- if ( usemecs )
- mkeccl( transset, tsptr, tecfwd, tecbck, numecs, 0 );
+ if ( usemecs )
+ mkeccl( transset, tsptr, tecfwd, tecbck, numecs, 0 );
- mkprot( tnxt + tmpbase, -numtemps, comstate );
+ mkprot( tnxt + tmpbase, -numtemps, comstate );
- /* we rely on the fact that mkprot adds things to the beginning
- * of the proto queue
- */
+ /* We rely on the fact that mkprot adds things to the beginning
+ * of the proto queue.
+ */
- numdiff = tbldiff( state, firstprot, tmp );
- mkentry( tmp, numecs, statenum, -numtemps, numdiff );
- }
+ numdiff = tbldiff( state, firstprot, tmp );
+ mkentry( tmp, numecs, statenum, -numtemps, numdiff );
+ }
-/* mv2front - move proto queue element to front of queue
- *
- * synopsis
- * int qelm;
- * mv2front( qelm );
- */
+/* mv2front - move proto queue element to front of queue */
void mv2front( qelm )
int qelm;
-
- {
- if ( firstprot != qelm )
{
- if ( qelm == lastprot )
- lastprot = protprev[lastprot];
+ if ( firstprot != qelm )
+ {
+ if ( qelm == lastprot )
+ lastprot = protprev[lastprot];
- protnext[protprev[qelm]] = protnext[qelm];
+ protnext[protprev[qelm]] = protnext[qelm];
- if ( protnext[qelm] != NIL )
- protprev[protnext[qelm]] = protprev[qelm];
+ if ( protnext[qelm] != NIL )
+ protprev[protnext[qelm]] = protprev[qelm];
- protprev[qelm] = NIL;
- protnext[qelm] = firstprot;
- protprev[firstprot] = qelm;
- firstprot = qelm;
+ protprev[qelm] = NIL;
+ protnext[qelm] = firstprot;
+ protprev[firstprot] = qelm;
+ firstprot = qelm;
+ }
}
- }
/* place_state - place a state into full speed transition table
*
- * synopsis
- * int *state, statenum, transnum;
- * place_state( state, statenum, transnum );
- *
* State is the statenum'th state. It is indexed by equivalence class and
* gives the number of the state to enter for a given equivalence class.
* Transnum is the number of out-transitions for the state.
@@ -823,45 +800,43 @@ int qelm;
void place_state( state, statenum, transnum )
int *state, statenum, transnum;
+ {
+ register int i;
+ register int *state_ptr;
+ int position = find_table_space( state, transnum );
- {
- register int i;
- register int *state_ptr;
- int position = find_table_space( state, transnum );
-
- /* base is the table of start positions */
- base[statenum] = position;
+ /* "base" is the table of start positions. */
+ base[statenum] = position;
- /* put in action number marker; this non-zero number makes sure that
- * find_table_space() knows that this position in chk/nxt is taken
- * and should not be used for another accepting number in another state
- */
- chk[position - 1] = 1;
+ /* Put in action number marker; this non-zero number makes sure that
+ * find_table_space() knows that this position in chk/nxt is taken
+ * and should not be used for another accepting number in another
+ * state.
+ */
+ chk[position - 1] = 1;
- /* put in end-of-buffer marker; this is for the same purposes as above */
- chk[position] = 1;
+ /* Put in end-of-buffer marker; this is for the same purposes as
+ * above.
+ */
+ chk[position] = 1;
- /* place the state into chk and nxt */
- state_ptr = &state[1];
+ /* Place the state into chk and nxt. */
+ state_ptr = &state[1];
- for ( i = 1; i <= numecs; ++i, ++state_ptr )
- if ( *state_ptr != 0 )
- {
- chk[position + i] = i;
- nxt[position + i] = *state_ptr;
- }
+ for ( i = 1; i <= numecs; ++i, ++state_ptr )
+ if ( *state_ptr != 0 )
+ {
+ chk[position + i] = i;
+ nxt[position + i] = *state_ptr;
+ }
- if ( position + numecs > tblend )
- tblend = position + numecs;
- }
+ if ( position + numecs > tblend )
+ tblend = position + numecs;
+ }
/* stack1 - save states with only one out-transition to be processed later
*
- * synopsis
- * int statenum, sym, nextstate, deflink;
- * stack1( statenum, sym, nextstate, deflink );
- *
* if there's room for another state on the "one-transition" stack, the
* state is pushed onto it, to be processed later by mk1tbl. If there's
* no room, we process the sucker right now.
@@ -869,34 +844,29 @@ int *state, statenum, transnum;
void stack1( statenum, sym, nextstate, deflink )
int statenum, sym, nextstate, deflink;
-
- {
- if ( onesp >= ONE_STACK_SIZE - 1 )
- mk1tbl( statenum, sym, nextstate, deflink );
-
- else
{
- ++onesp;
- onestate[onesp] = statenum;
- onesym[onesp] = sym;
- onenext[onesp] = nextstate;
- onedef[onesp] = deflink;
+ if ( onesp >= ONE_STACK_SIZE - 1 )
+ mk1tbl( statenum, sym, nextstate, deflink );
+
+ else
+ {
+ ++onesp;
+ onestate[onesp] = statenum;
+ onesym[onesp] = sym;
+ onenext[onesp] = nextstate;
+ onedef[onesp] = deflink;
+ }
}
- }
/* tbldiff - compute differences between two state tables
*
- * synopsis
- * int state[], pr, ext[];
- * int tbldiff, numdifferences;
- * numdifferences = tbldiff( state, pr, ext )
- *
* "state" is the state array which is to be extracted from the pr'th
* proto. "pr" is both the number of the proto we are extracting from
* and an index into the save area where we can find the proto's complete
* state table. Each entry in "state" which differs from the corresponding
* entry of "pr" will appear in "ext".
+ *
* Entries which are the same in both "state" and "pr" will be marked
* as transitions to "SAME_TRANS" in "ext". The total number of differences
* between "state" and "pr" is returned as function value. Note that this
@@ -905,23 +875,22 @@ int statenum, sym, nextstate, deflink;
int tbldiff( state, pr, ext )
int state[], pr, ext[];
+ {
+ register int i, *sp = state, *ep = ext, *protp;
+ register int numdiff = 0;
- {
- register int i, *sp = state, *ep = ext, *protp;
- register int numdiff = 0;
+ protp = &protsave[numecs * (pr - 1)];
- protp = &protsave[numecs * (pr - 1)];
+ for ( i = numecs; i > 0; --i )
+ {
+ if ( *++protp == *++sp )
+ *++ep = SAME_TRANS;
+ else
+ {
+ *++ep = *sp;
+ ++numdiff;
+ }
+ }
- for ( i = numecs; i > 0; --i )
- {
- if ( *++protp == *++sp )
- *++ep = SAME_TRANS;
- else
- {
- *++ep = *sp;
- ++numdiff;
- }
+ return numdiff;
}
-
- return ( numdiff );
- }