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