1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
24 /* Get statistics of a dictionary
26 ** Written by Kiem-Phong Vo (5/25/96)
30 static void dttstat(Dtstat_t
* ds
, Dtlink_t
* root
, int depth
, int* level
)
32 static void dttstat(ds
,root
,depth
,level
)
40 dttstat(ds
,root
->left
,depth
+1,level
);
42 dttstat(ds
,root
->right
,depth
+1,level
);
50 static void dthstat(reg Dtdata_t
* data
, Dtstat_t
* ds
, reg
int* count
)
52 static void dthstat(data
, ds
, count
)
61 for(h
= data
->ntab
-1; h
>= 0; --h
)
63 for(t
= data
->htab
[h
]; t
; t
= t
->right
)
76 int dtstat(reg Dt_t
* dt
, Dtstat_t
* ds
, int all
)
78 int dtstat(dt
, ds
, all
)
85 static int *Count
, Size
;
89 ds
->dt_n
= ds
->dt_max
= 0;
90 ds
->dt_count
= NIL(int*);
91 ds
->dt_size
= dtsize(dt
);
92 ds
->dt_meth
= dt
->data
->type
&DT_METHODS
;
97 if(dt
->data
->type
&(DT_SET
|DT_BAG
))
98 { dthstat(dt
->data
,ds
,NIL(int*));
99 if(ds
->dt_max
+1 > Size
)
102 if(!(Count
= (int*)malloc((ds
->dt_max
+1)*sizeof(int))) )
106 for(i
= ds
->dt_max
; i
>= 0; --i
)
108 dthstat(dt
->data
,ds
,Count
);
110 else if(dt
->data
->type
&(DT_OSET
|DT_OBAG
))
112 { dttstat(ds
,dt
->data
->here
,0,NIL(int*));
113 if(ds
->dt_n
+1 > Size
)
116 if(!(Count
= (int*)malloc((ds
->dt_n
+1)*sizeof(int))) )
121 for(i
= ds
->dt_n
; i
>= 0; --i
)
123 dttstat(ds
,dt
->data
->here
,0,Count
);
124 for(i
= ds
->dt_n
; i
>= 0; --i
)
125 if(Count
[i
] > ds
->dt_max
)
126 ds
->dt_max
= Count
[i
];
129 ds
->dt_count
= Count
;