Graphviz  2.41.20170921.2350
dtsize.c
Go to the documentation of this file.
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 
8 static int treecount(reg Dtlink_t* e)
9 { return e ? treecount(e->left) + treecount(e->right) + 1 : 0;
10 }
11 
12 int 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 }
#define reg
Definition: dthdr.h:14
#define DT_QUEUE
Definition: cdt.h:131
int size
Definition: cdt.h:73
#define DT_OSET
Definition: cdt.h:127
CDT_API int dtsize(Dt_t *)
Definition: dtsize.c:12
#define DT_STACK
Definition: cdt.h:130
#define DT_OBAG
Definition: cdt.h:128
#define DT_LIST
Definition: cdt.h:129
#define UNFLATTEN(dt)
Definition: dthdr.h:38
Dtlink_t * here
Definition: cdt.h:67
Definition: cdt.h:99
Dtdata_t * data
Definition: cdt.h:102
int type
Definition: cdt.h:66