Graphviz
12.0.1~dev.20240715.2254
Loading...
Searching...
No Matches
dtrenew.c
Go to the documentation of this file.
1
#include <
cdt/dthdr.h
>
2
#include <stddef.h>
3
4
/* Renew the object at the current finger.
5
**
6
** Written by Kiem-Phong Vo (5/25/96)
7
*/
8
9
void
*
dtrenew
(
Dt_t
* dt,
void
* obj)
10
{
11
void
*
key
;
12
Dtlink_t
*e, *t, **
s
;
13
Dtdisc_t
* disc = dt->
disc
;
14
15
UNFLATTEN
(dt);
16
17
if
(!(e = dt->
data
->
here
) ||
_DTOBJ
(e,disc->
link
) != obj)
18
return
NULL
;
19
20
if
(dt->
data
->
type
&
DT_QUEUE
)
21
return
obj;
22
else
if
(dt->
data
->
type
&(
DT_OSET
|
DT_OBAG
) )
23
{
if
(!e->
right
)
/* make left child the new root */
24
dt->
data
->
here
= e->left;
25
else
/* make right child the new root */
26
{ dt->
data
->
here
= e->
right
;
27
28
/* merge left subtree to right subtree */
29
if
(e->left)
30
{
for
(t = e->
right
; t->left; t = t->left)
31
;
32
t->left = e->left;
33
}
34
}
35
}
36
else
/*if(dt->data->type&(DT_SET|DT_BAG))*/
37
{
s
= dt->
data
->htab +
HINDEX
(dt->
data
->
ntab
,e->hash);
38
if
((t = *
s
) == e)
39
*
s
= e->
right
;
40
else
41
{
for
(; t->
right
!= e; t = t->
right
)
42
;
43
t->
right
= e->
right
;
44
}
45
key
=
_DTKEY
(obj,disc->
key
,disc->
size
);
46
e->hash =
dtstrhash
(
key
, disc->
size
);
47
dt->
data
->
here
=
NULL
;
48
}
49
50
dt->
data
->
size
-= 1;
51
return
dt->
meth
->
searchf
(dt, e,
DT_RENEW
) ? obj :
NULL
;
52
}
_DTKEY
#define _DTKEY(o, ky, sz)
Definition
cdt.h:177
DT_OBAG
#define DT_OBAG
Definition
cdt.h:126
dtstrhash
CDT_API unsigned int dtstrhash(void *, int)
Definition
dtstrhash.c:19
DT_RENEW
#define DT_RENEW
Definition
cdt.h:136
DT_OSET
#define DT_OSET
Definition
cdt.h:125
_DTOBJ
#define _DTOBJ(e, lk)
Definition
cdt.h:176
DT_QUEUE
#define DT_QUEUE
Definition
cdt.h:127
dthdr.h
HINDEX
#define HINDEX(n, h)
Definition
dthdr.h:25
UNFLATTEN
#define UNFLATTEN(dt)
Definition
dthdr.h:27
dtrenew
void * dtrenew(Dt_t *dt, void *obj)
Definition
dtrenew.c:9
key
disc key
Definition
exparse.y:214
NULL
node NULL
Definition
grammar.y:149
_dt_s
Definition
cdt.h:104
_dt_s::data
Dtdata_t * data
Definition
cdt.h:106
_dt_s::disc
Dtdisc_t * disc
Definition
cdt.h:105
_dt_s::meth
Dtmethod_t * meth
Definition
cdt.h:107
_dtdata_s::ntab
int ntab
Definition
cdt.h:82
_dtdata_s::here
Dtlink_t * here
Definition
cdt.h:77
_dtdata_s::type
int type
Definition
cdt.h:76
_dtdata_s::size
int size
Definition
cdt.h:83
_dtdisc_s
Definition
cdt.h:89
_dtdisc_s::size
int size
Definition
cdt.h:90
_dtdisc_s::key
int key
Definition
cdt.h:89
_dtdisc_s::link
int link
Definition
cdt.h:91
_dtlink_s
Definition
cdt.h:55
_dtlink_s::right
Dtlink_t * right
Definition
cdt.h:55
_dtmethod_s::searchf
Dtsearch_f searchf
Definition
cdt.h:70
s
Definition
grammar.c:93
lib
cdt
dtrenew.c
Generated by
1.9.8