Graphviz  2.41.20171026.1811
dtflatten.c
Go to the documentation of this file.
1 #include "dthdr.h"
2 
3 /* Flatten a dictionary into a linked list.
4 ** This may be used when many traversals are likely.
5 **
6 ** Written by Kiem-Phong Vo (5/25/96).
7 */
8 
10 {
11  reg Dtlink_t *t, *r, *list, *last, **s, **ends;
12 
13  /* already flattened */
14  if(dt->data->type&DT_FLATTEN )
15  return dt->data->here;
16 
17  list = last = NIL(Dtlink_t*);
18  if(dt->data->type&(DT_SET|DT_BAG))
19  { for(ends = (s = dt->data->htab) + dt->data->ntab; s < ends; ++s)
20  { if((t = *s) )
21  { if(last)
22  last->right = t;
23  else list = last = t;
24  while(last->right)
25  last = last->right;
26  *s = last;
27  }
28  }
29  }
30  else if(dt->data->type&(DT_LIST|DT_STACK|DT_QUEUE) )
31  list = dt->data->head;
32  else if((r = dt->data->here) ) /*if(dt->data->type&(DT_OSET|DT_OBAG))*/
33  { while((t = r->left) )
34  RROTATE(r,t);
35  for(list = last = r, r = r->right; r; last = r, r = r->right)
36  { if((t = r->left) )
37  { do RROTATE(r,t);
38  while((t = r->left) );
39 
40  last->right = r;
41  }
42  }
43  }
44 
45  dt->data->here = list;
46  dt->data->type |= DT_FLATTEN;
47 
48  return list;
49 }
CDT_API Dtlink_t * dtflatten(Dt_t *)
Definition: dtflatten.c:9
#define reg
Definition: dthdr.h:14
#define DT_SET
Definition: cdt.h:125
#define DT_BAG
Definition: cdt.h:126
#define DT_QUEUE
Definition: cdt.h:131
#define NIL(t)
Definition: dthdr.h:13
#define DT_STACK
Definition: cdt.h:130
Definition: grammar.c:79
#define RROTATE(x, y)
Definition: dthdr.h:47
#define DT_LIST
Definition: cdt.h:129
Dtlink_t * here
Definition: cdt.h:67
#define DT_FLATTEN
Definition: dthdr.h:22
int ntab
Definition: cdt.h:72
Definition: cdt.h:99
Dtdata_t * data
Definition: cdt.h:102
int type
Definition: cdt.h:66