Graphviz 12.0.1~dev.20240715.2254
Loading...
Searching...
No Matches
dtrestore.c
Go to the documentation of this file.
1#include <cdt/dthdr.h>
2#include <stddef.h>
3
4/* Restore dictionary from given tree or list of elements.
5** There are two cases. If called from within, list is nil.
6** From without, list is not nil and data->size must be 0.
7**
8** Written by Kiem-Phong Vo (5/25/96)
9*/
10
11int dtrestore(Dt_t* dt, Dtlink_t* list)
12{
13 Dtlink_t *t, **s, **ends;
14 int type;
15 Dtsearch_f searchf = dt->meth->searchf;
16
17 type = dt->data->type&DT_FLATTEN;
18 if(!list) /* restoring a flattened dictionary */
19 { if(!type)
20 return -1;
21 list = dt->data->here;
22 }
23 else /* restoring an extracted list of elements */
24 { if(dt->data->size != 0)
25 return -1;
26 type = 0;
27 }
28 dt->data->type &= ~DT_FLATTEN;
29
30 if(dt->data->type&DT_SET)
31 { dt->data->here = NULL;
32 if(type) /* restoring a flattened dictionary */
33 { for(ends = (s = dt->data->htab) + dt->data->ntab; s < ends; ++s)
34 { if((t = *s) )
35 { *s = list;
36 list = t->right;
37 t->right = NULL;
38 }
39 }
40 }
41 else /* restoring an extracted list of elements */
42 { dt->data->size = 0;
43 while(list)
44 { t = list->right;
45 searchf(dt, list, DT_RENEW);
46 list = t;
47 }
48 }
49 }
50 else
51 { if(dt->data->type&(DT_OSET|DT_OBAG))
52 dt->data->here = list;
53 else /*if(dt->data->type&(DT_LIST|DT_STACK|DT_QUEUE))*/
54 { dt->data->here = NULL;
55 dt->data->head = list;
56 }
57 if(!type)
58 dt->data->size = -1;
59 }
60
61 return 0;
62}
#define DT_OBAG
Definition cdt.h:126
#define DT_SET
Definition cdt.h:124
#define DT_RENEW
Definition cdt.h:136
#define DT_OSET
Definition cdt.h:125
void *(* Dtsearch_f)(Dt_t *, void *, int)
Definition cdt.h:49
#define DT_FLATTEN
Definition dthdr.h:18
int dtrestore(Dt_t *dt, Dtlink_t *list)
Definition dtrestore.c:11
expr procedure type
Definition exparse.y:211
node NULL
Definition grammar.y:149
Definition cdt.h:104
Dtdata_t * data
Definition cdt.h:106
Dtmethod_t * meth
Definition cdt.h:107
int ntab
Definition cdt.h:82
Dtlink_t * here
Definition cdt.h:77
int type
Definition cdt.h:76
int size
Definition cdt.h:83
Dtsearch_f searchf
Definition cdt.h:70
Definition grammar.c:93