Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
dtmethod.c
Go to the documentation of this file.
1#include <cdt/dthdr.h>
2#include <stdlib.h>
3
4/* Change search method.
5**
6** Written by Kiem-Phong Vo (05/25/96)
7*/
8
10{
11 Dtlink_t *list, *r;
12 Dtdisc_t* disc = dt->disc;
13 Dtmethod_t* oldmeth = dt->meth;
14
15 if(!meth || meth->type == oldmeth->type)
16 return oldmeth;
17
18 /* get the list of elements */
19 list = dtflatten(dt);
20
21 if (dt->data.type & DT_SET)
22 { if (dt->data.ntab > 0)
23 free(dt->data.htab);
24 dt->data.ntab = 0;
25 dt->data.htab = NULL;
26 }
27
28 dt->data.here = NULL;
29 dt->data.type = (dt->data.type & ~(DT_METHODS|DT_FLATTEN)) | meth->type;
30 dt->meth = meth;
31 if(dt->searchf == oldmeth->searchf)
32 dt->searchf = meth->searchf;
33
34 if(meth->type&(DT_OSET|DT_OBAG))
35 { dt->data.size = 0;
36 while(list)
37 { r = list->right;
38 meth->searchf(dt, list, DT_RENEW);
39 list = r;
40 }
41 }
42 else if(oldmeth->type&DT_SET)
43 { int rehash;
44 if((meth->type&DT_SET) && !(oldmeth->type&DT_SET))
45 rehash = 1;
46 else rehash = 0;
47
48 dt->data.size = 0;
49 dt->data.loop = 0;
50 while(list)
51 { r = list->right;
52 if(rehash)
53 { void* key = _DTOBJ(list,disc->link);
54 key = _DTKEY(key,disc->key,disc->size);
55 list->hash = dtstrhash(key, disc->size);
56 }
57 (void)meth->searchf(dt, list, DT_RENEW);
58 list = r;
59 }
60 }
61
62 return oldmeth;
63}
#define _DTKEY(o, ky, sz)
Definition cdt.h:169
#define DT_OBAG
Definition cdt.h:122
#define DT_SET
Definition cdt.h:120
CDT_API Dtlink_t * dtflatten(Dt_t *)
Definition dtflatten.c:10
CDT_API unsigned int dtstrhash(void *, int)
Definition dtstrhash.c:21
#define DT_RENEW
Definition cdt.h:131
#define DT_METHODS
Definition cdt.h:123
#define DT_OSET
Definition cdt.h:121
#define _DTOBJ(e, lk)
Definition cdt.h:168
#define DT_FLATTEN
Definition dthdr.h:18
Dtmethod_t * dtmethod(Dt_t *dt, Dtmethod_t *meth)
Definition dtmethod.c:9
static Dtdisc_t disc
Definition exparse.y:209
void free(void *)
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
int loop
Definition cdt.h:80
Dtsearch_f searchf
Definition cdt.h:66
int type
Definition cdt.h:67
Definition cdt.h:100
Dtmethod_t * meth
Definition cdt.h:103
Dtsearch_f searchf
Definition cdt.h:100
Dtdata_t data
sharable data
Definition cdt.h:102
Dtdisc_t * disc
Definition cdt.h:101
int key
Definition cdt.h:85
int size
Definition cdt.h:86
int link
Definition cdt.h:87