~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to cdt/dtstat.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This software may only be used by you under license from AT&T Corp.
 
3
    ("AT&T").  A copy of AT&T's Source Code Agreement is available at
 
4
    AT&T's Internet website having the URL:
 
5
    <http://www.research.att.com/sw/tools/graphviz/license/source.html>
 
6
    If you received this software without first entering into a license
 
7
    with AT&T, you have an infringing copy of this software and cannot use
 
8
    it without violating AT&T's intellectual property rights.
 
9
*/
 
10
#include        "dthdr.h"
 
11
 
 
12
#ifdef DMALLOC
 
13
#include "dmalloc.h"
 
14
#endif
 
15
 
 
16
/*      Get statistics of a dictionary
 
17
**
 
18
**      Written by Kiem-Phong Vo (5/25/96)
 
19
*/
 
20
 
 
21
#if __STD_C
 
22
static void dttstat(Dtstat_t* ds, Dtlink_t* root, int depth, int* level)
 
23
#else
 
24
static void dttstat(ds,root,depth,level)
 
25
Dtstat_t*       ds;
 
26
Dtlink_t*       root;
 
27
int             depth;
 
28
int*            level;
 
29
#endif
 
30
{
 
31
        if(root->left)
 
32
                dttstat(ds,root->left,depth+1,level);
 
33
        if(root->right)
 
34
                dttstat(ds,root->right,depth+1,level);
 
35
        if(depth > ds->dt_n)
 
36
                ds->dt_n = depth;
 
37
        if(level)
 
38
                level[depth] += 1;
 
39
}
 
40
 
 
41
#if __STD_C
 
42
static void dthstat(reg Dtdata_t* data, Dtstat_t* ds, reg int* count)
 
43
#else
 
44
static void dthstat(data, ds, count)
 
45
reg Dtdata_t*   data;
 
46
Dtstat_t*       ds;
 
47
reg int*        count;
 
48
#endif
 
49
{
 
50
        reg Dtlink_t*   t;
 
51
        reg int         n, h;
 
52
 
 
53
        for(h = data->ntab-1; h >= 0; --h)
 
54
        {       n = 0;
 
55
                for(t = data->htab[h]; t; t = t->right)
 
56
                        n += 1;
 
57
                if(count)
 
58
                        count[n] += 1;
 
59
                else if(n > 0)
 
60
                {       ds->dt_n += 1;
 
61
                        if(n > ds->dt_max)
 
62
                                ds->dt_max = n;
 
63
                }
 
64
        }
 
65
}
 
66
 
 
67
#if __STD_C
 
68
int dtstat(reg Dt_t* dt, Dtstat_t* ds, int all)
 
69
#else
 
70
int dtstat(dt, ds, all)
 
71
reg Dt_t*       dt;
 
72
Dtstat_t*       ds;
 
73
int             all;
 
74
#endif
 
75
{
 
76
        reg int         i;
 
77
        static int      *Count, Size;
 
78
 
 
79
        UNFLATTEN(dt);
 
80
 
 
81
        ds->dt_n = ds->dt_max = 0;
 
82
        ds->dt_count = NIL(int*);
 
83
        ds->dt_size = dtsize(dt);
 
84
        ds->dt_meth = dt->data->type&DT_METHODS;
 
85
 
 
86
        if(!all)
 
87
                return 0;
 
88
 
 
89
        if(dt->data->type&(DT_SET|DT_BAG))
 
90
        {       dthstat(dt->data,ds,NIL(int*));
 
91
                if(ds->dt_max+1 > Size)
 
92
                {       if(Size > 0)
 
93
                                free(Count);
 
94
                        if(!(Count = (int*)malloc((ds->dt_max+1)*sizeof(int))) )
 
95
                                return -1;
 
96
                        Size = ds->dt_max+1;
 
97
                }
 
98
                for(i = ds->dt_max; i >= 0; --i)
 
99
                        Count[i] = 0;
 
100
                dthstat(dt->data,ds,Count);
 
101
        }
 
102
        else if(dt->data->type&(DT_OSET|DT_OBAG))
 
103
        {       if(dt->data->here)
 
104
                {       dttstat(ds,dt->data->here,0,NIL(int*));
 
105
                        if(ds->dt_n+1 > Size)
 
106
                        {       if(Size > 0)
 
107
                                        free(Count);
 
108
                                if(!(Count = (int*)malloc((ds->dt_n+1)*sizeof(int))) )
 
109
                                        return -1;
 
110
                                Size = ds->dt_n+1;
 
111
                        }
 
112
 
 
113
                        for(i = ds->dt_n; i >= 0; --i)
 
114
                                Count[i] = 0;
 
115
                        dttstat(ds,dt->data->here,0,Count);
 
116
                        for(i = ds->dt_n; i >= 0; --i)
 
117
                                if(Count[i] > ds->dt_max)
 
118
                                        ds->dt_max = Count[i];
 
119
                }
 
120
        }
 
121
        ds->dt_count = Count;
 
122
 
 
123
        return 0;
 
124
}