1#include "dthdr.h"
2
3/* Return the # of objects in the dictionary
4**
5** Written by Kiem-Phong Vo (5/25/96)
6*/
7
8static int treecount(reg Dtlink_t* e)
9{ return e ? treecount(e->left) + treecount(e->right) + 1 : 0;
10}
11
12int dtsize(Dt_t* dt)
13{
14 reg Dtlink_t* t;
15 reg int size;
16
17 UNFLATTEN(dt);
18
19 if(dt->data->size < 0) /* !(dt->data->type&(DT_SET|DT_BAG)) */
20 { if(dt->data->type&(DT_OSET|DT_OBAG))
21 dt->data->size = treecount(dt->data->here);
22 else if(dt->data->type&(DT_LIST|DT_STACK|DT_QUEUE))
23 { for(size = 0, t = dt->data->head; t; t = t->right)
24 size += 1;
25 dt->data->size = size;
26 }
27 }
28
29 return dt->data->size;
30}
31