xref: /titanic_41/usr/src/lib/libast/common/cdt/dtsize.c (revision 3e14f97f673e8a630f076077de35afdd43dc1587)
1 /***********************************************************************
2 *                                                                      *
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                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #include	"dthdr.h"
23 
24 /*	Return the # of objects in the dictionary
25 **
26 **	Written by Kiem-Phong Vo (5/25/96)
27 */
28 
29 #if __STD_C
treecount(reg Dtlink_t * e)30 static int treecount(reg Dtlink_t* e)
31 #else
32 static int treecount(e)
33 reg Dtlink_t*	e;
34 #endif
35 {	return e ? treecount(e->left) + treecount(e->right) + 1 : 0;
36 }
37 
38 #if __STD_C
dtsize(Dt_t * dt)39 int dtsize(Dt_t* dt)
40 #else
41 int dtsize(dt)
42 Dt_t*	dt;
43 #endif
44 {
45 	reg Dtlink_t*	t;
46 	reg int		size;
47 
48 	UNFLATTEN(dt);
49 
50 	if(dt->data->size < 0) /* !(dt->data->type&(DT_SET|DT_BAG)) */
51 	{	if(dt->data->type&(DT_OSET|DT_OBAG))
52 			dt->data->size = treecount(dt->data->here);
53 		else if(dt->data->type&(DT_LIST|DT_STACK|DT_QUEUE))
54 		{	for(size = 0, t = dt->data->head; t; t = t->right)
55 				size += 1;
56 			dt->data->size = size;
57 		}
58 	}
59 
60 	return dt->data->size;
61 }
62