Graphviz 13.0.0~dev.20241220.2304
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))
54 { dt->data.here = NULL;
55 dt->data.head = list;
56 }
57 if(!type)
58 --dt->data.size;
59 }
60
61 return 0;
62}
#define DT_OBAG
Definition cdt.h:122
#define DT_SET
Definition cdt.h:120
#define DT_RENEW
Definition cdt.h:131
#define DT_OSET
Definition cdt.h:121
void *(* Dtsearch_f)(Dt_t *, void *, int)
Definition cdt.h:45
#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:208
node NULL
Definition grammar.y:163
int size
Definition cdt.h:79
Dtlink_t * here
Definition cdt.h:73
int type
Definition cdt.h:72
int ntab
Definition cdt.h:78
Dtsearch_f searchf
Definition cdt.h:66
Definition cdt.h:100
Dtmethod_t * meth
Definition cdt.h:103
Dtdata_t data
sharable data
Definition cdt.h:102
Definition grammar.c:93