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
9
Dtmethod_t
*
dtmethod
(
Dt_t
* dt,
Dtmethod_t
* meth)
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
}
_DTKEY
#define _DTKEY(o, ky, sz)
Definition
cdt.h:169
DT_OBAG
#define DT_OBAG
Definition
cdt.h:122
DT_SET
#define DT_SET
Definition
cdt.h:120
dtflatten
CDT_API Dtlink_t * dtflatten(Dt_t *)
Definition
dtflatten.c:10
dtstrhash
CDT_API unsigned int dtstrhash(void *, int)
Definition
dtstrhash.c:21
DT_RENEW
#define DT_RENEW
Definition
cdt.h:131
DT_METHODS
#define DT_METHODS
Definition
cdt.h:123
DT_OSET
#define DT_OSET
Definition
cdt.h:121
_DTOBJ
#define _DTOBJ(e, lk)
Definition
cdt.h:168
dthdr.h
DT_FLATTEN
#define DT_FLATTEN
Definition
dthdr.h:18
dtmethod
Dtmethod_t * dtmethod(Dt_t *dt, Dtmethod_t *meth)
Definition
dtmethod.c:9
disc
static Dtdisc_t disc
Definition
exparse.y:209
free
void free(void *)
NULL
node NULL
Definition
grammar.y:163
Dtdata_t::size
int size
Definition
cdt.h:79
Dtdata_t::here
Dtlink_t * here
Definition
cdt.h:73
Dtdata_t::type
int type
Definition
cdt.h:72
Dtdata_t::ntab
int ntab
Definition
cdt.h:78
Dtdata_t::loop
int loop
Definition
cdt.h:80
Dtmethod_t
Definition
cdt.h:66
Dtmethod_t::searchf
Dtsearch_f searchf
Definition
cdt.h:66
Dtmethod_t::type
int type
Definition
cdt.h:67
dt_s_
Definition
cdt.h:100
dt_s_::meth
Dtmethod_t * meth
Definition
cdt.h:103
dt_s_::searchf
Dtsearch_f searchf
Definition
cdt.h:100
dt_s_::data
Dtdata_t data
sharable data
Definition
cdt.h:102
dt_s_::disc
Dtdisc_t * disc
Definition
cdt.h:101
dtdisc_s_
Definition
cdt.h:85
dtdisc_s_::key
int key
Definition
cdt.h:85
dtdisc_s_::size
int size
Definition
cdt.h:86
dtdisc_s_::link
int link
Definition
cdt.h:87
dtlink_s_
Definition
cdt.h:51
dtlink_s_::right
Dtlink_t * right
Definition
cdt.h:51
lib
cdt
dtmethod.c
Generated by
1.9.8