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