File: inddeb.c

package info (click to toggle)
ted 2.6-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,928 kB
  • ctags: 8,734
  • sloc: ansic: 71,878; makefile: 2,363; sh: 159
file content (133 lines) | stat: -rw-r--r-- 3,225 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#   include	"config.h"

#   include	"indlocal.h"

/************************************************************************/
/*  Print a list of Nodes with their transitions.			*/
/************************************************************************/
void indTLprint( ind, tl )
IND *	ind;
int	tl;
    {
    TrieLink *	link= LINK(ind,tl);

    if  ( link->tl_to == TLgFREE )
	{ printf("\tLINK %6d FREE %d slots\n", tl, link->tl_key ); return; }
    if  ( link->tl_to == TLgUSED )
	{ printf("\tLINK %6d FREE %d slots\n", tl, link->tl_key ); return; }
    printf("\tLINK %6d '%c' -> %6d\n",
	tl, link->tl_key?link->tl_key:'#', link->tl_to );
    }

void indTNprint( ind, tn )
IND *	ind;
int	tn;
    {
    TrieNode *	node= NODE(ind,tn);
    int		transitions= node->tn_transitions;
    int		tl;

    printf( "NODE %6d: %3d transitions AT %6d %s %d items at %d\n",
	tn, node->tn_ntrans, transitions,
	(node->tn_flags&TNfACCEPTS)?"ACCEPTS":"INTERN",
	node->tn_nitem, node->tn_items );

    for ( tl= 0; tl < node->tn_ntrans; tl++ )
	{ indTLprint(ind,transitions+ tl); }

    if  ( node->tn_flags & TNfACCEPTS && node->tn_nitem > 0 )
	{
	int	nitem;
	int *	items;
	int	i;

	/*
	indITget( ind, tn, &nitem, &items );
	*/
	indGetItems( (void *)ind, tn, &nitem, &items );

	for ( i= 0; i < nitem; i++ )
	    { printf( "\t ITEM %7d\n", items[i] ); }
	}
    }

void indINDprint( ind )
IND *	ind;
    {
    int	tn;

    printf( "INDEX: root= %d, %d nodes, %d links\n",
	ind->ind_start, ind->ind_nnode, ind->indAllocatedLinks );

    for ( tn= 0; tn < ind->ind_nnode; tn++ )
	{ indTNprint( ind, tn ); }
    }

/************************************************************************/
/*									*/
/*  Count the different length of deterministic path in the automaton.	*/
/*									*/
/************************************************************************/

void indINDcount( IND *	ind )
    {
    int		tn;
    int		l;

    static int lengths[200];

    for ( tn= 0; tn < ind->ind_nnode; tn++ )
	{
	TrieNode *	node= NODE(ind,tn);

	if  ( node->tn_ntrans == 1 )
	    {
	    int		transitions= node->tn_transitions;
	    TrieLink *	link= LINK(ind,transitions);

	    l= 0;
	    while( node->tn_ntrans == 1 )
		{
		node= NODE(ind,link->tl_to); l++;
		transitions= node->tn_transitions;
		link= LINK(ind,transitions);
		}
	    lengths[l]++;
	    }
	}

    for ( l= 1; l < 199; l++ )
	{
	if  ( lengths[l] > 0 )
	    { printf( "%3d: %5d\n", l, lengths[l]- lengths[l+1] ); }
	}
    }

/************************************************************************/
/*  Print all possible words stored in a trie.				*/
/*  NOTE: The approach is naive and loops on cyclic structures.		*/
/************************************************************************/
void	indDump( ind, tn, level )
IND *	ind;
int	tn;
int	level;
    {
    static char	outbuf[400];
    TrieNode *	node;
    int		i;
    int		n;

    if  ( tn < 0 )
	{ return;	}
    node= NODE(ind,tn);
    n= node->tn_ntrans;

    if  ( node->tn_flags & TNfACCEPTS )
	{ outbuf[level]= '\0'; printf( "> %s\n", outbuf ); }

    for ( i= 0; i < n; i++ )
	{
	outbuf[level]= LINK(ind,node->tn_transitions+i)->tl_key;
	indDump( ind, LINK(ind,node->tn_transitions+i)->tl_to, level+ 1 );
	}
    }